Hey there to the StackOverFlow Community!
Let's talk decrypting a hash message with the RSA Public Key. When logging in to my application, the backend service provides me with an RSA Public Key which I save for future message decryption purposes. The backend then sends me an encrypted payload using the private key and I need to decrypt it using the stored public key.
I rely on the jsencrypt library for this encryption/decryption process. While the encryption task went smoothly using the encrypt function, I am encountering difficulties with decryption.
To troubleshoot, I attempted to decrypt the key from the backend service using online tools like this one, which successfully decrypted the hash message using the pre-stored public key.
Here's a glimpse of my current code:
decryptPayload(response: any) {
const key = response.key;
const payload = response.payload;
const publicRsaKey = sessionStorage.getItem('rsa_public_key');
const rsaDecrypt = new JSEncrypt();
rsaDecrypt.setPublicKey(`-----BEGIN PUBLIC KEY-----
${publicRsaKey}
-----END PUBLIC KEY-----`);
const decryptAes = rsaDecrypt.decrypt(key);
console.log('decrypted key: ', decryptAes);
}
Despite this implementation, the decrypted key
always returns false
, indicating decryption failure.
Has anyone encountered a similar issue while decrypting with the jsencrypt library using the public key? And is it indeed possible to decrypt a hash message using the RSA public key?