Socket
Socket
Sign inDemoInstall

jfpe

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jfpe

format-preserving encryption (FPE) by node.js


Version published
Maintainers
1
Created
Source

jfpe

A simple format-preserving encryption (FPE) implement by Node.js.

In cryptography, format-preserving encryption (FPE), refers to encrypting in such a way that the output (the ciphertext) is in the same format as the input (the plaintext). The meaning of "format" varies. Typically only finite domains are discussed, for example:

  • To encrypt a 16-digit credit card number so that the ciphertext is another 16-digit number.
  • To encrypt an English word so that the ciphertext is another English word.
  • To encrypt an n-bit number so that the ciphertext is another n-bit number (this is the definition of an n-bit block cipher).

For such finite domains, and for the purposes of the discussion below, the cipher is equivalent to a permutation of N integers {0, ... , N−1} where N is the size of the domain.

By default, this lib will encrypt & decrypt by domain of 0-9A-Za-z and 5 prefix-ivs.

Install

$ npm i -S jfpe

Usage

const FPE = require('jfpe')

const fpe = new FPE('my-secret-key')
const encrypted = fpe.encrypt('Hello_World-123')
const decrypted = fpe.decrypt(encrypted)

console.log('encrypted:', encrypted) // HOJBBGwSGXBKv981
console.log('decrypted:', decrypted) // hello_world-123

Customize domain and iv list

const myDomain = '0123456789abcdefghijklmnopqrstuvwxyz'.split('')
const myIvs = [
  '31c10d883e45c3cde515ba968140aae3',
  '2fc1bee21fdd7335242efe6f5a46a7be',
  '7eb06befa9b2d8fa5ee225ccd27d8039'
]
const fpe = new FPE('my-secret-key_custom', {
  domain: myDomain,
  ivs: myIvs
})
const encrypted = fpe.encrypt('helloworld123')
console.log(encrypted)

While, iv random bytes can be gen by:

const iv = crypto.randomBytes(16).toString('hex') // be6794609d987fdab5bcc754899c6ca0

Keywords

FAQs

Package last updated on 24 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc