Ad

Java's RSA/ECB/OAEPWithSHA-256AndMGF1Padding Equivalent In Node.js

- 1 answer

The data decryption will run in JAVA using RSA/ECB/OAEPWithSHA-256AndMGF1Padding algorithm. So I have to encrypt the data with public key using the algorithm equivalent to RSA/ECB/OAEPWithSHA-256AndMGF1Padding in node.js.

I tried with crypto.publicEncrypt(key, buffer) which uses crypto.constants.RSA_PKCS1_OAEP_PADDING which is not similar to the above algorithm. So I need algorithm equivalent to "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" or how to achieve the same in node.js

Ad

Answer

I finally found the answer. Equivalent to "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" can be achieved via node-forge npm module. https://www.npmjs.com/package/node-forge#rsa

    // encrypt data with a public key using RSAES-OAEP/SHA-256/MGF1-SHA-1
// compatible with Java's RSA/ECB/OAEPWithSHA-256AndMGF1Padding
var encrypted = publicKey.encrypt(bytes, 'RSA-OAEP', {
  md: forge.md.sha256.create(),
  mgf1: {
    md: forge.md.sha256.create()
  }
});

Thank you

Ad
source: stackoverflow.com
Ad