加密脚本
var param = {};
if(pm.request.method === 'GET'){
param = pm.request.url.query;
}else if(pm.request.method === 'POST'){
param = pm.request.body;
}
if(param === null || param === undefined){
param = {};
}
var cryptoJs = require("crypto-js");
var publicKey = '';
var signKey = '';
publicKey = cryptoJs.enc.Base64.parse(publicKey);
var encryptedData = cryptoJs.AES.encrypt(JSON.stringify(param), publicKey, {mode: cryptoJs.mode.ECB,padding: cryptoJs.pad.Pkcs7,length: 128}).toString();
var timestamp = _.now();
var sign = cryptoJs.SHA1(encryptedData + timestamp + signKey).toString();
var requestParam = {'encryptedData':encryptedData,'sign':sign,'timestamp':timestamp};
if(pm.request.method === 'GET'){
pm.request.url.query = requestParam;
}else if(pm.request.method === 'POST'){
pm.request.body = requestParam;
}
解密脚本
if(pm.response.code == 201){
var cryptoJs = require("crypto-js");
console.log(cryptoJs);
var publicKey = '';
var signKey = '';
publicKey = cryptoJs.enc.Base64.parse(publicKey);
var data = cryptoJs.AES.decrypt(pm.response.json(), publicKey, {mode: cryptoJs.mode.ECB,padding: cryptoJs.pad.Pkcs7,length: 128});
var tmpdata = data.toString(cryptoJs.enc.Utf8);
pm.response.json() = JSON.parse(data.toString(cryptoJs.enc.Utf8));
}