MD5Encoder加密支持utf-8

 2 
 3 import java.security.MessageDigest;
 4 
 5 public class MD5Encoder {
 6     
 7     public static String encode(String string) throws Exception {
 8         byte[] hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
 9         StringBuilder hex = new StringBuilder(hash.length * 2);
10         for (byte b : hash) {
11             if ((b & 0xFF) < 0x10) {
12                 hex.append("0");
13             }
14             hex.append(Integer.toHexString(b & 0xFF));
15         }
16         return hex.toString();
17     }
18 }

 

posted on 2016-06-14 19:56  oooo呼呼  阅读(475)  评论(0编辑  收藏  举报