Open alish1129 opened 2 years ago
Why sometimes do you write crypto
and other cryptoJS
? Maybe should you use always cryptoJS
?
where const cryptoJS = require("crypto-js");
so, your code should be:
function decryptCode (code) {
try {
const parsedBase64Key = cryptoJS.enc.Base64.parse(secretKey);
const decryptedData = cryptoJS.AES.decrypt(code, parsedBase64Key, {
mode: cryptoJS.mode.ECB,
padding: cryptoJS.pad.Pkcs7
});
const decryptedText = decryptedData.toString(cryptoJS.enc.Utf8);
console.log(`Cipher Decrypting was Successful`);
return decryptedText;
} catch (error) {
throw Error(`Error while decrypting the cipher code: ${error}`);
}
}
Finally, is code
parameter a Base64 encoded bundle?
I am trying to decode cipher code generated from Java using CryptoJS. The code used to encrypt is:
This decrypt method in Java works fine.
However, when I try to decrypt it from Javascript using CryptoJS. I am getting an Error: Malformed UTF-8 data.
This is my JS decrypt function:
const cryptoJS = require('crypto-js')
decryptCode("7ksKkAFXC6B_V_8Tjb1Eqg");
What am I doing wrong?