Format-preserving encryption implementation
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib update dependencies May 14, 2018
test
.gitignore Initial commit Nov 21, 2016
.prettierignore
.prettierrc update deps Nov 25, 2018
.travis.yml
README.md Prettier changes Nov 25, 2018
license
package-lock.json update deps Nov 25, 2018
package.json

README.md

node-fpe

Build Status styled with prettier

Simple format-preserving encryption implementation

In general, format-preserving encryption is a type of encryption such that the output (the ciphertext) is in the same format as the input (the plaintext).

This library uses a simple FPE from a prefix cipher. The method is only useful for a small domains, for example numbers or alphanumeric.

Usage

Example:

cipher with default domain ([0-9]) and default encryption alg (aes-256-cbc):

const fpe = require('node-fpe');
const cipher = fpe({ password: 'secret' });

cipher.encrypt('1234567');
// '4185730'

cipher.decrypt('4185730');
// '1234567'

cipher with custom domain ([A-E]) and default encryption alg (aes-256-cbc):

const fpe = require('node-fpe');
const cipher = fpe({ password: 'secret', domain: ['A', 'B', 'C', 'D', 'E'] });

cipher.encrypt('BEEBEE');
// 'CBBCBB'

cipher.decrypt('CBBCBB');
// 'BEEBEE'

Options

Options to pass on to node-fpe are:

  • password: mandatory. a secret used in the underlying block cipher.
  • algorithm: optional. the underlying block cipher used. similar to the input to node's crypto.createCipher(). default: aes-256-cbc
  • domain: optional. an array of characters used as the FPE domain. default: 0-9 digits