1.0.1 • Published 3 years ago
ffxradix-js v1.0.1
FFXRadix
This is a JavaScript translation from
jan2000
's repo ffxradix
A JavaScript implementation of the FFX[radix] Scheme of The FFX Mode of Operation for Format-Preserving Encryption. Also known as mode FF1 in NIST Special Publication 800-38G: Recommendation for Block Cipher Modes of Operation: Methods for Format-Preserving Encryption
Encrypt and decrypt a message with a radix between 2 to 62 and preserves its length. Messages to be enciphered under
FFX[radix] are regarded as strings of characters drawn from the alphabet Chars = {0, 1, 2,...,radix − 1}
.
Scheme FFX[radix] does its work using an AES-based balanced Feistel network. If the message length is odd, an
alternating, maximally-balanced Feistel scheme is used instead.
Set up
npm i # or install
Example Usage
"use strict";
const path = require("path");
// assuming this script is at the root of the repo
const FFXRadix = require(path.join(__dirname, "./src/FFXRadix"));
const hex2bin = require(path.join(__dirname, "./lib/php2js")).hex2bin;
// Key must be a 16 byte long string if AES-128 (default) is used
var key = hex2bin("00000000000000000000000000000000");
// Tweak can be anything
var tweak = hex2bin("0123456789abcdef");
var radix = 10;
var ffx = new FFXRadix();
// Encrypt a 16 decimal number (radix = 10)
var enc = ffx.encrypt("1".padStart(16, "0"), radix, key, tweak);
// Outputs 1299047952447293
console.log(enc);
// Decrypt
var dec = ffx.decrypt(enc, radix, key, tweak);
// Outputs 0000000000000001
console.log(dec);