MD5+salt 工具类
Posted draymonder
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MD5+salt 工具类相关的知识,希望对你有一定的参考价值。
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Encrypt {
private static String []hex = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
private static String MD5init(String text) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte []bytes = md5.digest(text.getBytes("utf8"));
StringBuffer sb = new StringBuffer();
for(byte b : bytes) {
int tmp = b;
if(tmp < 0) tmp += 128;
int index1 = tmp / 16;
int index2 = tmp % 16;
sb.append(hex[index1]).append(hex[index2]);
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
public static String encrypt(String message) {
return MD5init(MD5init(message+"draymonder")+"draymonder");
}
}
以上是关于MD5+salt 工具类的主要内容,如果未能解决你的问题,请参考以下文章