@nghiaht/fpe

2020.0.2 • Public • Published

fpe

Format-preserving encryption (FPE).

Current implementations:

Installing

npm install @nghiaht/fpe

Example

Use aes-256-ecb as prefix cipher:

const FPEPrefixCipher = require("@nghiaht/fpe").FPEPrefixCipher;
const cipher = new FPEPrefixCipher.Cipher({
    domain: "abc123".split(""),
    enc_func: function (v) {
      return FPEPrefixCipher.encrypt_aes_256_ecb("password", v);
    },
});

const input = "abc123";
const encrypted = cipher.encrypt(input);
const decrypted = cipher.decrypt(encrypted);

Please provide your custom prefix cipher (block cipher, etc..) as an agument enc_func in the Cipher constructor:

function my_enc_func(v) {
    return my_encrypt_aes("password", v);
}

const cipher = new FPEPrefixCipher.Cipher({
    domain: "abc123".split(""),
    enc_func: my_enc_func
});

Raise error when your input is not in the input domain:

const cipher = new FPEPrefixCipher.Cipher({
    domain: "1234567890".split(""),
    enc_func: function (v) {
      return v;
    },
});

cipher.encrypted("abc123")  // throw Error("bad_input_or_invalid_domain"), "abc" not in domain: "1234567890"

Testing

npm run test

Potential Actions

  • Implement more FPE constructions.
  • Prefix cipher: implement more or generalize into a base encoder function supporting various block cipher algorithms.

Readme

Keywords

Package Sidebar

Install

npm i @nghiaht/fpe

Weekly Downloads

1

Version

2020.0.2

License

ISC

Unpacked Size

8.01 kB

Total Files

5

Last publish

Collaborators

  • nghiaht