MD5Encoder加密工具

来源:互联网 发布:网络音乐管理黑名单 编辑:程序博客网 时间:2024/05/16 08:26
import java.security.MessageDigest;


public class MD5Encoder {
/**
* Md5Encoder

* @param string
* @return
* @throws Exception
*/
public static String encode(String string) throws Exception {
byte[] hash = MessageDigest.getInstance("MD5").digest(
string.getBytes("UTF-8"));
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
if ((b & 0xFF) < 0x10) {
hex.append("0");
}
hex.append(Integer.toHexString(b & 0xFF));
}
return hex.toString();
}
}
0 0