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));
}
}