Skip to content Skip to sidebar Skip to footer

How To Decrypt Aes With Cryptojs

I'm trying for some time to decrypt a message in AES that use a Java app , but it never works . Can someone help me? var options = { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.

Solution 1:

varCryptoJS = require("crypto-js");

var key = CryptoJS.enc.Utf8.parse('b75524255a7f54d2726a951bb39204df');
var iv  = CryptoJS.enc.Utf8.parse('1583288699248111');
var text = "My Name Is Nghĩa";


var encryptedCP = CryptoJS.AES.encrypt(text, key, { iv: iv });
var decryptedWA = CryptoJS.AES.decrypt(encryptedCP, key, { iv: iv});
var cryptText = encryptedCP.toString();
console.log(cryptText);
console.log(decryptedWA.toString(CryptoJS.enc.Utf8));

//Decode from text    var cipherParams = CryptoJS.lib.CipherParams.create({
     ciphertext: CryptoJS.enc.Base64.parse(cryptText )
});
var decryptedFromText = CryptoJS.AES.decrypt(cipherParams, key, { iv: iv});
console.log(decryptedFromText.toString(CryptoJS.enc.Utf8));

Solution 2:

try this to encrypt data

vardata = CryptoJS.AES.encrypt(message, key);
data = data.toString()

then decrypt it like this

var decr = CryptoJS.AES.decrypt(data, key);
decr = decr.toString(CryptoJS.enc.Utf8);

Post a Comment for "How To Decrypt Aes With Cryptojs"