Code
import java.util.*;
import java.io.*;
import java.security.*;
public class MD5 {
public static String hex(byte[] array) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).toUpperCase().substring(1,3));
}
return sb.toString();
}
public static String md5 (String message) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");\\想用SHA加密的话就把MD5换成SHA吧
return hex (md.digest(message.getBytes("CP1252")));
} catch (NoSuchAlgorithmException e) {
} catch (UnsupportedEncodingException e) {
}
return null;
}
public static void main(String[] args) {
System.out.println (md5 ("LiChao"));
}
}