Crypto-js: how to use aes ecb mode with 256bit

1.2k Views Asked by At

my code:

function AesDecrypt(word, keyIn) {
  let decrypt = CryptoJS.AES.decrypt(word, keyIn, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return decrypt.toString(CryptoJS.enc.Utf8);
}

function AesEncrypt(word, keyIn) {
  let encrypted = CryptoJS.AES.encrypt(word, keyIn, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
}

when using:

let msg = {
  'OS': 'iOS'
}
msg = JSON.stringify(msg)
let key = 'FE7A45426AFF5D14E52897E134F5CC33'
const aes_msg = AesEncrypt(msg, key)
 # U2FsdGVkX1/QZRpRuRajXR7UdoXxxYR/lcyoYItxTrI=
const msg_d = AesDecrypt(aes_msg, key)
 # {"OS":"iOS"}

as above, problem solved but it conflicts with online-AES. i do ont know how and where it goes wrong.

0

There are 0 best solutions below