Simon Lang
Simon Lang

Reputation: 42755

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.

Upvotes: 3

Views: 2372

Answers (1)

Maarten Bodewes
Maarten Bodewes

Reputation: 94038

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)

Upvotes: 4

Related Questions