API 连接网关脚本 JSON Datapower 中的 AES 加密解密

AES Encryption Decryption in API Connect Gateway Script JSON Datapower

如何在 api 连接网关脚本中使用 aes encrption/decryption.. 下面是我尝试过的过程和我得到的错误帮助我理解这个问题

const crypto = require('crypto');
var encryptionKey = '0123456789abcd0123456789';
var iv = '12345678';
var plainText = 'Testing';
var cipher = crypto.createCipheriv('aes128-cbc',encryptionKey,Buffer.from(iv, 'utf8'));
var ciph = cipher.update(plainText,'utf8','hex');
consle.error(cipher.final('hex'));

响应---错误"Named shared secret key '0123456789abcd0123456789' not found"

谁能分享给我aes算法加密解密的脚本?

来自 Node.Js 文档

The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings, Buffers, TypedArray, or DataViews. If the cipher does not need an initialization vector, iv may be null.

根据文档,keyiv 必须都是 UTF8 字符串、Buffer、TypeArray 或 DataView。您可能需要将 he key 更改为 Buffer 或将 iv 更改为字符串。

var cipher = crypto.createCipheriv('aes128-cbc', 
                                   Buffer.from(encryptionKey, 'utf8'),
                                   Buffer.from(iv, 'utf8'));