Node crypto - unable to reverse encryption
cryptography, javascript, node.js
Solution
utf8 is not a valid cipher.final() option, you want binary. Try this.
var cipher = crypto.createCipheriv('rc4', 'secret', '');
crypt = cipher.update('hello', 'utf8', 'binary');
crypt += cipher.final('binary');
var decipher = crypto.createDecipheriv('rc4','secret', '');
data = decipher.update(crypt, 'binary', 'utf8');
data += decipher.final('utf8');
console.log(data);
Problem
Why does this not print "hello"? ``` var cipher = crypto.createCipheriv('rc4', 'secret', ''); crypt = cipher.update('hello', 'binary', 'utf8'); crypt += cipher.final('utf8'); var decipher = crypto.createDecipheriv('rc4','secret', ''); data = decipher.update(crypt, 'binary', 'utf8'); data += decipher.final('utf8'); console.log(data); // prints e/l ```