流沙团
md5加密代码
2016-9-19 流沙团
package com.gyarmy.test;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Utils {

public static String md5(String value){

String md5Str = "";

try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] myValue = value.getBytes();
byte[] md5Value = md5.digest(myValue);

//输出md5的值
for(byte b : md5Value){
//System.out.print(Integer.toHexString(b)+" - ");
int d = b & 0xff;
String hexString = Integer.toHexString(d);
if(hexString.length() == 1){
hexString = "0" + hexString;
}
//md5String.append(hexString);
md5Str+=hexString;
}

} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return md5Str+"";
}

}
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容