简体   繁体   中英

node crypto decipher final fail

So I am using node crypto library to decipher a binary file that is encrypted by some other software which I have no control over. Using the following code, I am able to decrypt it successfully:

decipher = crypto.createDecipheriv('aes-128-ecb', password, iv);
decrypted = decipher.update(body, 'binary', 'utf8');

This is great, however it appears there are about 11 characters truncated from the end of my decrypted text. Which is weird because it's over 11200 characters of plaintext. Now I suspect the reason is because I don't have this line:

decrypted += decipher.final('utf8');

However, if I add that line, I get the error TypeError: DecipherFinal fail

I have tried different output encodings and without the IV, but with no luck. I have also read this question: What's wrong with nodejs crypto decipher? which seems like the same issue, however I don't understand the steps I am supposed to take on the openssl command line, or how that would affect my node program.

Have you tried setting auto padding to false? By default it sets it seems set to true (see below), so if the other party does not pad using the default padding (whatever that is, probably PKCS#7 padding), then the result should fail...

decipher.setAutoPadding(auto_padding=true)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM