postman以及Jmeter加密
var ass= CryptoJS.MD5("加密内容").toString(); //将内容加密后转化为字符串,结果为32位小写
var ass= CryptoJS.MD5("加密内容").toString().toUpperCase();//将加密后的转化为字符串,结果为32位大写
console.log(ass);
jmeter-MD5加密: 方法一:
${_digest(MD5,加密内容,,,)}
方法二: 1.添加前置处理器-BeanShellPreProcess 2.关键内容:
import org.apache.commons.codec.digest.DigestUtils;
String reqSign= DigestUtils.md5Hex(str).toUpperCase();
reqsign = hmac.new(secretkey.encode('utf-8'),reqcontent.encode('utf-8'), hashlib.sha256).hexdigest()
postman加密: Pre-request Script 编辑关键内容:
var reqSign=(CryptoJS.HmacSHA256(reqContent,secretKey)).toString() // 加密 转化为字符串
var has16 =reqSign.toString(CryptoJS.enc.Hex) // 转化为16进制
jmeter加密: 1.JSR预处理程序-选择java脚本 2.关键内容:
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import org.apache.jmeter.config.*;
// 签名
try {
Mac mac = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
mac.init(secretKeySpec);
byte[] array = mac.doFinal(reqContent.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte item : array) {
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
}
reqSign = sb.toString();
} catch (Exception e) {
e.printStackTrace();
reqSign = "Exception";
}
- .toLowerCase() java内将字符串转化为小写
- .toUpperCase() java内将字符串转化为大写
|