Node.js - Set padding in crypto module
11,994
http://nodejs.org/api/crypto.html#crypto_cipher_setautopadding_auto_padding_true
When you disable auto-padding, you can write any padding you wish by simply writing to cipher
(which is a stream).
Author by
dsw88
Updated on June 21, 2022Comments
-
dsw88 almost 2 years
I've been looking over the docs for the crypto module in Node, and I'm trying to figure out how to set the padding when doing symmetric encryption. I'm trying to use AES-128-ECB, with PKCS5 padding.
I can't see anywhere that it allows you to specify padding. I would certainly hope this is possible to do using this library. How can I specify padding for symmetric encryption in the crypto module?
-
ntoskrnl over 10 yearsOr in other words, if you leave auto-padding enabled, the plaintext will be PKCS#5 padded automatically.
-
dsw88 over 10 yearsOk, that's helpful, thanks! How would I write the correct padding to the string? I'm not super good with cryptography, so writing that correctly is difficult to know how to do.
-
Mil0R3 over 10 years@ntoskrnl since in iOS the default padding is PKCS#7 and can not be changed, so how to set padding to PKCS#7 in node.js?
-
dsw88 over 10 years@Veelian Yeah I did, but that was to use PKCS5 padding in Node, which is what I needed. I'm not sure how to set it to PKCS7.
-
ntoskrnl over 10 years@dsw88 PKCS#5 padding is the same as PKCS#7 padding.
-
dsw88 over 10 yearsAh I didn't know that, thanks! I'm not super familiar with padding schemes, or other encryption details very much for that matter.
-
Aborn Jiang about 8 yearsfor block-size 128-bit, there are no difference between PKCS#5 and PKCS#7.