I have this code where the secret_key is of 32 length, cipherText variable will have the encrypted data which need to be decoded
const secret_key = "Whispersofthewindechoedthroughth";
const decryptData = (cipherText) => {
const bytes = CryptoJS.AES.decrypt(cipherText, secret_key);
let message = bytes.toString(CryptoJS.enc.Utf8);
return message;
};
console.log("decrypt: " +decryptData(cipherText));
Can anyone suggest the solutions?
I attempted to encrypt data in C++ so that it could be decrypted in Node.js using CryptoJS. I used PKCS5_PBKDF2_HMAC to generate a 32-byte key and initialized the IV as 0 with a size of 16 bytes. MD5 was used for hashing in PKCS5_PBKDF2_HMAC. For encryption, I employed EVP_aes_256_cbc(), and for base64 encoding, I utilized OpenSSL BIOs. However, decryption failed in Node.js.
In Nodejs to encrypt the data, we make this function:-
The message is 10 digit number, SecuritySalt length is 128, secret_key length is 32
var CryptoJS = require("crypto-js");
SecuritySalt = "Amidst the bustling city streets, a solitary figure found solace in the melody of raindrops dancing upon the cobblestones.sdwe2q";
secret_key = "Whispersofthewindechoedthroughth";
const encryptData = (message) => {
return CryptoJS.AES.encrypt(
SecuritySalt + message,
secret_key
).toString();
};
let message = "1111111111";
console.log("encrypt message :" + encryptData(message));
I need this same implementation in c++ using openssl.
Mihir Aryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.