当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - node crypto.createDecipher wrong final block length error

问题描述:

I'm using the following code to first encipher and then decipher.

var fs = require('fs');

var crypto = require('crypto');

var ws = fs.createWriteStream('message.txt');

var rs = fs.createReadStream('message.txt');

var passPhrase = 'password';

process.stdin.pipe(crypto.createCipher('aes256', passPhrase)).pipe(ws);

ws.on('finish', function() {

rs.pipe(crypto.createDecipher("aes256", passPhrase)).pipe(process.stdout);

});

I'm calling the code as:

echo "randomstring" | node crypt.js

But I keep getting the following error:

events.js:85

throw er; // Unhandled 'error' event

^

Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length

at Error (native)

at Decipher.Cipher._flush (crypto.js:177:28)

at Decipher.<anonymous> (_stream_transform.js:130:12)

at Decipher.g (events.js:199:16)

at Decipher.emit (events.js:104:17)

at prefinish (_stream_writable.js:474:12)

at finishMaybe (_stream_writable.js:482:7)

at endWritable (_stream_writable.js:493:3)

at Decipher.Writable.end (_stream_writable.js:459:5)

at ReadStream.onend (_stream_readable.js:505:10)

I am just deciphering the output of createCipher, why am I still getting the wrong final block length error?

Contents of message.txt come out garbled on my terminal

[email protected]:~/stream-adventure$ cat message.txt

�[��Z�*3��Kv�

[email protected]:~/stream-adventure$ wc -c message.txt

16 message.txt

分享给朋友:
您可能感兴趣的文章:
随机阅读: