UNPKG

node-fnr

Version:

Format-preserving encryption (FPE), small cipher (< 128 bits), for anonymization.

36 lines (35 loc) 1.47 kB
"use strict"; const addon = require('../build/Release/fnr-native'); ; class Fnr { /** * Inicialize FCR cipher. * @param data_bitsize Size of data pieces to en/decrypt in bits. Must be between 1 and 128 (inclusive). * @param passwd_bitsize Size of the secret password in bits. 128, 192 or 256. * @param tweak_bytesize Size of the possibly public tweak in bytes. */ constructor(data_bitsize, passwd_bitsize, tweak_bytesize) { this._addonInstance = new addon.Fnr(data_bitsize, passwd_bitsize, tweak_bytesize); } /** * Encrypt data by the FCR cipher. * @param data Buffer of the data to encrypt (in place). * @param passwd Buffer of the secret password. * @param tweak_str Buffer of the possibly public tweak. * @param data_count Number of the data pieces to encrypt in the `data` buffer. */ encrypt(data, passwd, tweak_str, data_count) { this._addonInstance.encrypt(data, passwd, tweak_str, data_count); } /** * Decrypt data by the FCR cipher. * @param data Buffer of the data to decrypt (in place). * @param passwd Buffer of the secret password. * @param tweak_str Buffer of the possibly public tweak. * @param data_count Number of the data pieces to decrypt in the `data` buffer. */ decrypt(data, passwd, tweak_str, data_count) { this._addonInstance.decrypt(data, passwd, tweak_str, data_count); } } module.exports = Fnr;