码迷,mamicode.com
首页 > 其他好文 > 详细

MD5加密

时间:2017-12-08 14:18:18      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:字符   auth   指定   throws   return   cep   on()   十六   style   


import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
* @author admin
*/
public class Md5Encryption {
private Md5Encryption() {

}

public static String getEncryption(String originString)
throws UnsupportedEncodingException {
String result = "";
if (originString != null) {
try {
// 指定加密的方式为MD5
MessageDigest md = MessageDigest.getInstance("MD5");
// 进行加密运算
byte[] bytes = md.digest(originString.getBytes("ISO8859-1"));
for (int i = 0; i < bytes.length; i++) {
// 将整数转换成十六进制形式的字符串 这里与0xff进行与运算的原因是保证转换结果为32位
String str = Integer.toHexString(bytes[i] & 0xFF);
if (str.length() == 1) {
str += "F";
}
result += str;
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
return result;
}

public static void main(String[] args) throws UnsupportedEncodingException {
String password = Md5Encryption.getEncryption("111111");
System.out.println(password);
System.out.println(Md5Encryption.getEncryption(password));
}
}

MD5加密

标签:字符   auth   指定   throws   return   cep   on()   十六   style   

原文地址:http://www.cnblogs.com/tobiasy/p/8004293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!