jmeter添加外部MD5加密jar包
公司最新项目要求对接口参数进行md5加密,大概思路:现将输入参数先进行ASCLL再进行MD5加密一、使用eclipse编写MD5加密方法(附上本人代码)
package com.md5;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
public class TestMd5 {
public static String md5(String[] value) {
StringBuilder result = new StringBuilder();
String re_md5 = new String();
String sign;
String arr;
String signKey = "68c163f20f994e82a09c41cbe71ea5ac";
long nonce_str=System.currentTimeMillis();
sign=nonce_str+signKey;
if (value.length==0) {
//String re_md5 = new String();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(sign.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b;
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
re_md5 = buf.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
// return re_md5.toUpperCase();
}else {
Arrays.sort(value);
for(int i=0;i<value.length;i++){
result.append(value);
}
String str = result.toString();
arr=str+nonce_str+signKey;
//return result.toString();
//return arr;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(arr.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b;
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
re_md5 = buf.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
// return re_md5.toUpperCase();
}
return re_md5.toUpperCase();
}
}二、导出jar包
三、将jar包添加到jmeter的lib/ext目录下面
四、新建jmeter的BeanShell Sampler进行调用
支持分享
页:
[1]