📄 encrypter.java
字号:
package com.hongsoft.res.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Encrypter {
public static final String encodeHex(byte[] bytes) {
StringBuffer buf = new StringBuffer(bytes.length * 2);
int i;
for (i = 0; i < bytes.length; i++) {
if ( ( (int) bytes[i] & 0xff) < 0x10) {
buf.append("0");
}
buf.append(Long.toString( (int) bytes[i] & 0xff, 16));
}
return buf.toString();
}
/**
* MD5加密方法
* @param data 需要加密的数据
* @return 加密后的数据
*/
public synchronized static final String hashByMD5(String data) {
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
// Now, compute hash.
digest.update(data.getBytes());
return encodeHex(digest.digest());
}
catch (NoSuchAlgorithmException nsae) {
System.err.println("Failed to load the MD5 MessageDigest. " +
"will be unable to function normally.");
nsae.printStackTrace();
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -