Node.js - Set padding in crypto module

dsw88 picture dsw88 · Sep 24, 2013 · Viewed 11.1k times · Source

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?

Answer

Nitzan Shaked picture Nitzan Shaked · Sep 24, 2013

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).