首页 > 开发 > Java > 正文

JAVA 的MD5加密算法源代码

2020-02-05 14:04:36
字体:
来源:转载
供稿:网友
import java.security.*;
import java.security.spec.*;

class md5_test{

public final static string md5(string s){
char hexdigits[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
'e', 'f'};
try {
byte[] strtemp = s.getbytes();
messagedigest mdtemp = messagedigest.getinstance("md5");
mdtemp.update(strtemp);
byte[] md = mdtemp.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexdigits[byte0 >>> 4 & 0xf];
str[k++] = hexdigits[byte0 & 0xf];
}
return new string(str);
}
catch (exception e){
return null;
}
}
public static void main(string[] args){
//md5_test aa = new md5_test();

system.out.print(md5_test.md5("xx"));
}



菜鸟学堂:
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表