You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Crypto-JS与Marketing Cloud(AMPScript)进行AES加解密适配问题

用Crypto-JS对接Marketing Cloud(AMPScript)加解密问题

我在用Crypto-JS处理Marketing Cloud(AMPScript)的加解密数据时遇到了麻烦。查库文档的时候发现根本没提IV的用法,网上的各种指南又乱七八糟的。一开始试了简单的加解密流程,结果解密出来全是空的,完全不对。

后来感谢Topaco帮忙,把密钥改成12字符长度后,加解密终于能正常跑了,同时解密部分还得改成传入CipherParams对象才行。

我还得确认对方的参数具体怎么用、有没有多次加密操作,之后会更新问题进展。

以下是我的代码:

const key = enc.Utf8.parse('Harold%Finch');
const iv = enc.Utf8.parse('11111111111111111111111111111111');
const secret = enc.Utf8.parse('secret@email.com');
const encrypted = AES.encrypt(secret, key, {
  iv: iv,
  mode: mode.CBC,
  padding: pad.Pkcs7,
});

const encryptedString = encrypted.toString();
// "2VxmNeqlTolVpgHrk+tdEO3+xS8XOjClikUjB+zAGis="

// 将base64编码字符串转为CipherParams对象
const ciphertext = enc.Base64.parse(encryptedString);
const cipherParams = lib.CipherParams.create({ ciphertext });

const decrypted = AES.decrypt(cipherParams, key, {
  iv: iv,
  mode: mode.CBC,
  padding: pad.Pkcs7,
});

// 将解密后的数据转为UTF-8字符串
const decryptedString = decrypted.toString(enc.Utf8);

console.info('decrypted', decryptedString);
// "secret@email.com"

对方端代码如下:

set @encAES = EncryptSymmetric(@str, "aes", @null, @password, @null, @salt, @null, @initVector)

现在两边的结果还是对不上,我正在查文档确认对方的默认配置(比如填充方式之类的)。

内容的提问来源于stack exchange,提问作者Sampgun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 11:40:21