node.js - NodeJS AES 256 hex decrypt error -
good day. want use nodejs module crypto decode encoded string. string encoded aes 256 ecb , have hex. attempts did nothing, got null string instead of errors. 'require' crypto, no open-ssl.
hex: 820d4da01ce75046c399ca314c5428c6af8d69c6573b4de5a6942a5277936f56
key: 7y05r9qwkaikgihh4vaw19x1zuknr21y
here's nodejs code.
var algorithm = 'aes-256-ecb', password = '7y05r9qwkaikgihh4vaw19x1zuknr21y', encstring = '820d4da01ce75046c399ca314c5428c6af8d69c6573b4de5a6942a5277936f56' var decipher = crypto.createdecipher(algorithm,password); var dec = decipher.update(encstring,'hex','utf8'); dec += decipher.final('utf8'); console.log(dec);
and have error.
error: error:06065064:digital envelope routines:evp_decryptfinal_ex:bad decrypt.
need please.
update
after fome hours , priceless advices maarten bodewes , this topic, working solution.
var encstring=req.query.d; console.log(encstring); var algorithm = 'aes-256-ecb', password = new buffer('7y05r9qwkaikgihh4vaw19x1zuknr21y', 'binary'); var decipher=crypto.createdecipheriv(algorithm, password.tostring('binary'), ''); decipher.setautopadding(false); var dec = decipher.update(encstring,'hex','utf8'); dec += decipher.final('utf8'); console.log(dec);
you'll have use createdecipher
algorithm, key , iv arguments. iv ignored, set 16 0 bytes sure. if use 2 argument function key put through password based key derivation function (pbkdf). , decryption incorrect key of course results in failure.
make sure switch off padding if decryption fails , see if resulting plaintext makes sense.