项目作者: mderazon

项目描述 :
Format preserving string substitution encryption
高级语言: JavaScript
项目地址: git://github.com/mderazon/node-fpe.git
创建时间: 2016-11-21T22:27:07Z
项目社区:https://github.com/mderazon/node-fpe

开源协议:MIT License

下载


node-fpe

Build status npm Version License: MIT

Format preserving string substitution encryption

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 substitution cipher algorithm. Read more about the security of this library in the dedicated section below.

Usage

Example:

cipher with default domain ([0-9])

  1. import fpe from 'node-fpe';
  2. const cipher = fpe({ secret: 'secret!' });
  3. cipher.encrypt('1234567');
  4. // '7130548'
  5. cipher.decrypt('7130548');
  6. // '1234567'

cipher with a custom domain ([A-E])

  1. import fpe from 'node-fpe';
  2. const cipher = fpe({ secret: 'secret!', domain: ['A', 'B', 'C', 'D', 'E'] });
  3. cipher.encrypt('BEEBEE');
  4. // 'ABBABB'
  5. cipher.decrypt('ABBABB');
  6. // 'BEEBEE'

Options

Options to pass on to node-fpe are:

  • secret: mandatory. a secret used in the underlying hash function.
  • domain: optional. an array of characters used as the FPE domain. default: 0-9 digits

Security

This module is using the term format-preserving encryption, however it is not a proper fpe implementation. It is basically a substitution cipher, you can use it to scramble and de-scramble strings but it is not recommended to use it with anything sensitive as the encryption is weak.

For fpe, there are other libraries available: