1. jsp中如何使用自带的md5类进行加密
jsp端实现md5加密就是jsp的java段代码来实现的,引入md5加密类,然后调用该类相应的方法就ok了,如果是输出的时候要注意的是别转换为字符串,如果jdk5.0以上的话
System.out.printf("%x",“加密过的变量”);
out.printf("%x",“加密过的变量”);
2. jsp中怎么实现MD5加密
写编写一个MD5加密工具类
通过import方式将MD5加密工具类引入到jsp中,然后使用MD5工具类进行加密
下面是MD5加密工具类代码
importjava.security.MessageDigest;
publicclassMD5Util{
(byteb[]){
StringBufferresultSb=newStringBuffer();
for(inti=0;i<b.length;i++)
resultSb.append(byteToHexString(b[i]));
returnresultSb.toString();
}
(byteb){
intn=b;
if(n<0)
n+=256;
intd1=n/16;
intd2=n%16;
returnhexDigits[d1]+hexDigits[d2];
}
publicstaticStringMD5Encode(Stringorigin,Stringcharsetname){
StringresultString=null;
try{
resultString=newString(origin);
MessageDigestmd=MessageDigest.getInstance("MD5");
if(charsetname==null||"".equals(charsetname))
resultString=byteArrayToHexString(md.digest(resultString
.getBytes()));
else
resultString=byteArrayToHexString(md.digest(resultString
.getBytes(charsetname)));
}catch(Exceptionexception){
}
returnresultString;
}
[]={"0","1","2","3","4","5",
"6","7","8","9","a","b","c","d","e","f"};
publicstaticvoidmain(String[]args){
Strings="appid=wxc7dac6b76548e969&attach=106&auth_code=130099732281083883&body=医泰天下远程会诊-20161019162200QCVV&mch_id=1393510702&nonce_str=&out_trade_no=20161019162200QCVV&time_expire=20161028192424&time_start=20161028182424&total_fee=1&key=";
System.out.println(MD5Encode(s,null));
}
}