1

While I was going through a piece of code in JAVA for encryption there is padding mechanism we can provide while creating cipher instance.

        final Cipher cipher = Cipher.getInstance("AES/CBC/ISO10126Padding");

Here we can specify the padding to be used.

How can i achieve the same in Node.js?

Use Case: I am decrypting the data which i have encrypted via JAVA using this method.

Note: In Java i can encrypt & decrypt by creating the cipher instance the above provided way and getting success response. Let me know if any other info required.

Digvijay Rathore
  • 637
  • 1
  • 6
  • 21
  • 1
    The *crypto* module of NodeJS uses PKCS#7 padding by default. If a different padding should be applied, the padding can be disabled with [`setAutoPadding(false)`](https://nodejs.org/api/crypto.html#ciphersetautopaddingautopadding) and a custom padding/unpadding can be implemented (which is not very elaborate). ISO 10126 is described e.g. [here](https://en.wikipedia.org/wiki/Padding_(cryptography)#ISO_10126). Alternatively, another NodeJS library can be used, e.g. [*CryptoJS*](https://cryptojs.gitbook.io/docs/#block-modes-and-padding). – Topaco Dec 06 '22 at 17:13

0 Answers0