Skip to content

Node v8.9.0 Error: Invalid key length crypto.createCipheriv #953

@ronovar

Description

@ronovar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions