import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Encrypter {
private static String[] hexMap = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
String raw = "1";
byte[] bs = md5.digest(raw.getBytes());
StringBuilder sBuilder = new StringBuilder();
for (byte b : bs) {
sBuilder.append(byteToHex(b));
}
System.out.println(sBuilder.toString().toLowerCase());
} catch (NoSuchAlgorithmException e) {
// TODO: handle exception
}
}
private static String byteToHex(byte b) {
// return String.format("%02x", b);
int i = b >= 0 ? b : b + 256;
return hexMap[i >> 4] + hexMap[i % 16];
}
}
网友评论