sample code:
var CryptoJS = require("crypto-js");
let secretKey = 'yourSecretKey';
function decrypt(aesStr, key) {
return CryptoJS.AES.decrypt(
aesStr,
CryptoJS.enc.Utf8.parse(padding(key)),
{
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
}
).toString(CryptoJS.enc.Utf8)
}
function padding(key) {
return key.padEnd(32, '\0');
}
//decrypt("encryptedData", secretKey)
Here we choose AES-256 to encrypt / decrypt the secure information. When using AES, the length of the secretKey is important. The length of secretKey in AES-128 is 16 bits, and in AES-256 is 32 bits.
And in our case, the length of secretKey is no enough. So we will use the function padding to fill in the missing length.
source: CSDN: AES解密,key长度不够16处理