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"));
}
}
文章来源:
http://www.cnblogs.com/xiaoao808/archive/2008/08/04/1260376.html
posted on 2008-08-04 20:25
破名超难起 阅读(110)
评论(0) 编辑 收藏