Node crypto decrypt final failure

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

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

      

This is great, however, it looks like about 11 characters are truncated from the end of my decrypted text. This is weird because it is over 11200 plain text characters. Now, I suspect that the reason is that I do not have this line:

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

      

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

I have tried different output encodings and without IV, but no luck. I also read this question: What is the problem with decrypting nodejs encryption? which seems to be the same problem, however I don't understand what steps I should take from the openssl command line or how it will affect my node program.

+3


source to share


1 answer


Have you tried setting autocomplete to false? By default, it sets it to true (see below), so unless the other side is using the pad using the default padding (whatever it may be PKCS # 7 padding), the result should be unsuccessful .. ...



decipher.setAutoPadding(auto_padding=true)

+4


source







All Articles