Skip to content

Anchakor/node-fnr

Repository files navigation

node-fnr

Node-js bindings for libFNR - A reference implementation for FNR encryption scheme.

FNR is a block cipher to encrypt small domain objects (< 128 bits) like IPv4 addresses, MAC addreses, Serial numbers, Account ids, Credit Card numbers etc. while preserving their lengths (and formats if needed). Useful for data anonymization.

See Format-preserving encryption.

NPM

Installation

Requires C library libfrn, which in turn requires openssl > 1.0.1e (installed in the system as dynamic shared libraries).

npm install node-fnr

Tested on Linux. Shouldn't be hard to make work on other platforms (PRs welcome).

Usage

const Fnr = require('node-fnr');

const data_bitsize = 16; // ... other variables
const fnr = new Fnr(data_bitsize, passwd_bitsize, tweak_bytesize);

const input = [0,1,65535];

const data = Buffer.alloc(data_bytesize * input.length);
for (let index = 0; index < input.length; index++) {
	data.writeUInt16BE(input[index], index * data_bytesize);
}

fnr.encrypt(data, passwd, tweak_str, input.length);
// now `data` is encrypted, read it with data.readUInt16BE()
// decrypt method has the same signature

See also the test code.

Development

npm install # building
npm link typescript # linking global typescript
npm run test

Updating dependencies. Use:

npm outdated

Possibly update package.json for major upgrades, then run:

rm node_modules/typescript; npm update; npm install; npm link typescript
npm run test

About

Node-js bindings for libFNR, a reference implementation for FNR encryption scheme.

Resources

License

Stars

Watchers

Forks

Packages

No packages published