-
Notifications
You must be signed in to change notification settings - Fork 300
Description
I have the following code that encrypt strings:
var crypto = require('crypto'),
algorithm = 'aes-128-cbc',
key = new Buffer('9vApxLk5G3PAsJrM', 'utf8'),
iv = new Buffer('FnJL7EDzjqWjcaY9', 'utf8');
function encrypt(text, key){
/* GET - crypted */
try {
var cipher = crypto.createCipheriv(algorithm, key, iv),
crypted = cipher.update(text, 'utf8', 'hex');
crypted += cipher.final('hex');
return crypted;
} catch(e) { return console.log(e)}
}
console.log(encrypt('blablabla', key))
And when i run this code in node v8.9.0 i get this error:
Error: Invalid key length
at new Cipheriv (crypto.js:219:16)
at Object.Cipheriv (crypto.js:217:12)
i try different key and iv lengths but i always get same error...so what it needs to be written key length?
I need to use crypto.createCipheriv because crypto.createCipher is depricied in new node version and new node version as describe developrs is 20% faster that previus version.