node-mac-crypt
v1.0.0
Published
Simple NodeJS Crypt Package with Mac Sign
Downloads
5
Readme
node-mac-crypt
Simple NodeJS Crypt Package with Mac Sign.
Usage
const crypto = require('crypto');
const MacCrypt = require('node-mac-crypt');
const crypt = new MacCrypt({
key: 'my_secret_password',
iv: crypto.randomBytes(16)
});
// String:
const message = 'My Secret Message!';
console.log(`Original Message: '${message}'`);
const encrypted = crypt.encrypt(message);
console.log(`Encrypted Message: '${encrypted}'`);
const decrypted = crypt.decrypt(encrypted);
console.log(`Decrypted Message: '${decrypted}'`);
// JSON:
const json = {data: 'My Secret Data!'};
console.log(`Original JSON Data:`, json);
const json_encrypted = crypt.encrypt(json);
console.log(`Encrypted JSON Data: '${json_encrypted}'`);
const json_decrypted = crypt.decrypt(json_encrypted);
console.log(`Decrypted JSON Data:`, json_decrypted);
Options
key
{base64 string|Buffer} -- secret key.iv
{base64 string|Buffer} -- cipher iv (16 bytes length).cipher
{string} -- cipher algorithm (default'aes-256-cbc'
).mac_size
{integer} -- mac sign size (default6
).mac_separator
{string} -- mac sign separator (default'::'
).key_length
{integer} -- secret key length in bytes (default32
).serialize
{function} -- message serialize method (defaultJSON.stringify
).unserialize
{function} -- message unserialize method (defaultJSON.parse
).