1.0.2 • Published 3 years ago

node-fnr v1.0.2

Weekly downloads
11
License
LGPL-2.1-or-later
Repository
github
Last release
3 years ago

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.

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