好的,看起来在引擎盖下面
   
    EncryptSymmetric
   
   中的方法
   
    AMPScript
   
   从创建密钥
   
    password
   
   和
   
    salt
   
   ,使用
   
    PBKDF2
   
   密钥推导(如@Topaco所述)。
  
  
   所以我们也需要这样做。
我正在使用
   
    crypto-js
   
   因为我有一组在前端和边缘中间件之间共享的编码-解码功能,但如果您在后端,则可以使用
   
    出生地的
   
   
    crypto
   
   的实施
   
    节点
   
   .
  
  
   原始AMPScript代码:
  
    %%[ 
    set @str = [EmailAddress]
    set @password="xyQ8n55tKi$@@4dy"
    set @initVector='198e3f0733ec4791'
    set @salt = "c2dc41eeab1e513a"  
    set @encAES = EncryptSymmetric(@str, "aes", @null, @password, @null, @salt, @null, @initVector)
    set @decAES = DecryptSymmetric(@encAES, "aes", @null, @password, @null, @salt, @null, @initVector)
  ]%%
    import { PBKDF2, AES, enc, mode, pad, algo } from 'crypto-js';
  const str = '[email protected]';
  const password = 'xyQ8n55tKi$@@4dy';
  const initVector = '198e3f0733ec4791';
  const salt = 'c2dc41eeab1e513a';
  // Encrypting the string using AES
  const encAES = encryptAES(str, password, salt, initVector);
  console.info('ENC AES', encAES);
  // Decrypting the encrypted string using AES
  const decAES = decryptAES(encAES, password, salt, initVector);
  console.info('DEC AES', decAES);
  function buildKey(password, salt) {
    return PBKDF2(password, enc.Hex.parse(salt), {
      keySize: 256 / 32,
      iterations: 1000,
      hasher: algo.SHA1,
    });
  }
  function encryptAES(data, password, salt, initVector) {
    return AES.encrypt(data, buildKey(password, salt), {
      iv: enc.Hex.parse(initVector),
      mode: mode.CBC,
      padding: pad.Pkcs7,
    }).toString();;
  }
  function decryptAES(data, password, salt, initVector) {
    return AES.decrypt(data, buildKey(password, salt), {
      iv: enc.Hex.parse(initVector),
      mode: mode.CBC,
      padding: pad.Pkcs7,
    }).toString(enc.Utf8);
  }
  
   
    他们说他们不能使用16字节的IV,而我们坚持使用32字节。我将来会检查这个。