forge
forge copied to clipboard
Encryption in Node decryption in Java getting error like SYSTEM Error Error Performing RSA Encryption javax.crypto.BadPaddingException: Decryption error
we are facing the problem in RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING encryption in node.js decryption in java.
below i can share my code in node:
var nodeForgeRsaEncryption = function (data,publicKeyPem){
var buf = forge.util.createBuffer(data, 'utf8');
publicKey = forge.pki.publicKeyFromPem(publicKeyPem);
let datas_temp = publicKey.encrypt(buf.bytes(),'RSA-OAEP',{
md: forge.md.sha256.create(),
mgf1: {
md: forge.md.sha1.create()
}
});
datas_temp = forge.util.encode64(datas_temp);
return datas_temp;
};
For decryption purpose i can use online tool to check the decryption part below i can share the link which i use to test the java decryption link - https://8gwifi.org/RSAFunctionality?keysize=4096
public and private key available in link itself can you guide me how to fix this issue
It happened to me too, did you solve it? Can you provide a reference?
function RSAOAEPPadding(data) {
const publicKeyPem = Your public key PEM format data
const publicKey = forge.pki.publicKeyFromPem(publicKeyPem)
var buf = forge.util.createBuffer(data, 'utf8');
const encryptedBytes = publicKey.encrypt(buf.bytes(), 'RSA-OAEP', { md: forge.md.sha256.create(), mgf1: { md: forge.md.sha1.create() } })
return forge.util.encode64(encryptedBytes) }
Check the PEM format