全部 ApiPost使用 后端 前端 接口测试 IOS Android 数据库 2022 测试技术 工具
问答 / 问答详情

[已处理] AES-GCM加密怎么实现

接口测试 135次浏览

项目中前后端使用了AES-GCM加密方式,求助怎么在预处理脚本中实现

| 0 收藏

5 个回答

const crypto = require('crypto'); // 密钥和初始化向量(IV) const key = crypto.randomBytes(32); // AES-256,所以密钥长度为32字节 const iv = crypto.randomBytes(12); // GCM模式的IV通常推荐为12字节 // 要加密的数据 const plaintext = '这是一个需要加密的消息'; // 加密 const cipher = crypto.createCipheriv('aes-256-gcm', key, iv); let encrypted = cipher.update(plaintext, 'utf8', 'hex'); encrypted += cipher.final('hex'); const authTag = cipher.getAuthTag(); console.log('加密后的数据:', encrypted); console.log('认证标签:', authTag.toString('hex')); // 解密 const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv); decipher.setAuthTag(authTag); let decrypted = decipher.update(encrypted, 'hex', 'utf8'); decrypted += decipher.final('utf8'); console.log('解密后的数据:', decrypted);



可以试一下

可是引用node的依赖吗 ,require('crypto');就报错了

AES-GCM加密怎么实现

我们好像没有这个加密,这个是我问的chat,可能不支持;使用内置 JS 类库 | Apipost支持的加密都在这里了

我们好像没有这个加密,这个是我问的chat,可能不支持;使用内置 JS 类库 | Apipost支持的加密都在这里了

最终实现:通过前置处理调用其他接口返回了加密串

Apipost 私有化火热进行中

撰写答案

只服务于

前后端、移动端、测试人员

提问题 发布您遇到的Bug和问题,上万名大牛和开发者来帮您解决!