When the user try to authenticate the first time and fail/success, then, try again/logout, the server is stopped and throw this error:
crypto.js:279
var ret = this._binding.update(data, inputEncoding);
^
TypeError: error:00000000:lib(0):func(0):reason(0)
at Decipher.Cipher.update (crypto.js:279:27)
All function well each time restart the app.
The Code:
var algorithm = 'aes-256-cbc';
var inputEncoding = 'utf8';
var outputEncoding = 'hex';
var crypto = require('crypto'),
key = process.env.SUPER_SECRET_KEY,
cipher = crypto.createCipher(algorithm, key),
decipher = crypto.createDecipher(algorithm, key);
exports.cipherData = function(pass){
var encryptedPass = cipher.update(pass, inputEncoding, outputEncoding);
encryptedPass += cipher.final(outputEncoding);
}
exports.decipherData = function(pass){
var decryptedPass = decipher.update(pass, outputEncoding, inputEncoding);
decryptedPass += decipher.final(inputEncoding);
console.log(decryptedPass);
}