data-encryptor
Version:
Encrypts data to be stored into databases & removes links to file with encrypting them
27 lines (23 loc) • 695 B
JavaScript
var crypto = require('crypto');
var encrypt = function(text, cipher, algorithm) {
if (!algorithm) {
var algorithm = 'aes-256-ctr';
}
var cipher = crypto.createCipher(algorithm, cipher)
var crypted = cipher.update(text, 'utf8', 'hex')
crypted += cipher.final('hex');
return crypted;
};
var decrypt = function(text, cipher, algorithm) {
if (!algorithm) {
var algorithm = 'aes-256-ctr';
}
var decipher = crypto.createDecipher(algorithm, cipher)
var dec = decipher.update(text, 'hex', 'utf8')
dec += decipher.final('utf8');
return dec;
};
module.exports = {};
module.exports.text = {};
module.exports.text.encrypt = encrypt;
module.exports.text.decrypt = decrypt;