Decryption js side fails with error:1C800064:Provider routines::bad decrypt #5124
Replies: 1 comment
-
|
This is a JavaScript code error, not a POCO bug. POCO's encryption is working correctly. The Problem: In your const decryptedStr = decrypt(encrypted_payload, g_encMethod, g_key, g_iv);But The Fix: Decode the base64 string to a Buffer before decrypting: // In your /send endpoint, change:
const decryptedStr = decrypt(encrypted_payload, g_encMethod, g_key, g_iv);
// To:
const encryptedBuffer = Buffer.from(encrypted_payload, 'base64');
const decryptedStr = decrypt(encryptedBuffer, g_encMethod, g_key, g_iv);Why it works locally in JS: Your local JS encrypt/decrypt test probably passes the Buffer directly without going through JSON/base64 serialization. Why C++ works: POCO correctly encrypts and base64-encodes the data. Your MD5 integrity check passes, proving the base64 string arrives intact. This is a common pitfall when working with binary data in JavaScript - always ensure you're using the correct encoding/decoding at each step. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
Decryption fails on the Node.js side and throws the following exception:
error:1C800064:Provider routines::bad decrypt
To Reproduce
Encrypt a string on the C++ side using POCO, then attempt to decrypt the encrypted string on the JavaScript side.
CODE:
Cpp side:
JavaScript code:
Expected behavior
At js side, Decrypted string should be same as original string before encryption from c++ side.
Logs
Screenshots

Please add relevant environment information:
Additional context
I'm attempting to encrypt a JSON object on the C++ side using POCO and then send the encrypted data (along with the payload) to the server. On the JavaScript side, both the base64-encoded string and the raw encrypted data match the output from C++, which confirms the data is transmitted correctly.
However, when I try to decrypt the data in JavaScript, I get the following error:
error:1C800064:Provider routines::bad decrypt
I'm unsure why the decryption fails in JavaScript. For context:
Encryption and decryption on the C++ side work perfectly.
Similarly, both encryption and decryption in JavaScript also work as expected.
The issue only occurs when encrypting in C++ and attempting to decrypt that encrypted data in JavaScript.
Note: I am using the same key, iv and encryption AES like 256.
I'd greatly appreciate any guidance on how to resolve this issue.
Thanks a lot in advance to this amazing community!
Beta Was this translation helpful? Give feedback.
All reactions