I'm having some trouble with using a public key from Java to encrypt within NodeJS.
I've created an RSA key within keytool
and output the public key as a base64 encoded string.
Base64.Encoder encoder = Base64.getEncoder();
byte[] pubKeyBytes = publicKey.getEncoded();
String pubKeyBase64 = encoder.encodeToString(pubKeyBytes);
I then took the the base64 encoded public key, wrapped it in -----BEGIN PUBLIC KEY-----
and -----END PUBLIC KEY-----
and used it to encrypt, then base64 encode a string within node.
const encryptedBuffer = crypto.publicEncrypt(encodedPublicKey, buffer);
const encryptedEncodedText = encryptedBuffer.toString("base64");
When I try to decrypt the encryptedEncodedText
(base64 decoding first) within Java, it throws a BadPadding
exception. Interestingly, if I export the private key to a PEM, Node can't decrypt with it either.
Any help would be appreciated!