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

如何对参数进行RSA加密传输

ApiPost使用 2762次浏览

如何对参数进行RSA加密传输

| 1 收藏

4 个回答

在脚本里定义吧

通过使用 https://github.com/travist/jsencrypt 实现信息加密。

首先在当前环境中定义一个变量JSEncrypt,内容即为JSEncrypt的所有内容,eval之后就可以直接调用了,核心是eval这个JSEncrypt,放在哪儿不重要。

贴一段我在Postman中的使用方法吧,已验证可用,ApiPost与Postman使用起来差别不大。

var window = {};
var navigator = { appName: "Postman", userAgent: "Postman" };
eval(pm.environment.get("JSEncrypt"));
var encrypt = new window.JSEncrypt({ "log": true });
encrypt.setPublicKey(pm.environment.get("PUBLIC_KEY"));
# 我的参数是json格式,需要这么获取
var requestBody = JSON.parse(pm.request.body.raw);
var password = requestBody.password;
console.log("用户登录密码明文信息:", password);
var passwordEncrypted = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(encrypt.encrypt(password)));
console.log("用户登录密码密文信息:", passwordEncrypted);
pm.environment.set("PASSWORD_ENCRYPTED", passwordEncrypted);
# 此时,已实现将请求体中的明文密码(requestBody.password)加密为密文(passwordEncrypted)并存储到了PASSWORD_ENCRYPTED中


如有疑问,可以发邮件联系我:xiaguliuxiang@foxmail.com

安装jsencrypt插件 https://module.apipost.cn/details.html?id=1

插件安装不了咋回事?点击安装就跳到登录,登陆完还是登录??@悬崖之上

Apipost 私有化火热进行中

撰写答案

只服务于

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

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