一个利用byte2hexString的简单MD5的应用,把你的密码加密
import java.security.MessageDigest;
public static String MD5Encode(String sourceString) {
String resultString = null;
try{
resultString=new String(sourceString);
MessageDigest md = MessageDigest.getInstance("MD5");
resultString=byte2hexString(md.digest(resultString.getBytes()));
}catch (Exception ex) {
}
return resultString;
}
public staticfinal String byte2hexString(byte[] bytes) {
StringBuffer buf = new StringBuffer(bytes.length * 2);
for (int 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();
}
public staticvoid main(String[] args) throws Exception {
System.out.println(MD5Encode("abc"));
System.out.println(MD5Encode("hello"));
System.out.println(MD5Encode("123456"));
System.out.println(MD5Encode("你好Blog"));
}
结果:
900150983cd24fb0d6963f7d28e17f72
5d41402abc4b2a76b9719d911017c592
e10adc3949ba59abbe56e057f20f883e
2fc0228c7266d61d184dcf2a6b3b81d3
posted on 2006-04-27 11:47
surffish 阅读(258)
评论(0) 编辑 收藏