android 项目学习随笔十九(MD5)

import java.security.MessageDigest;

public class MD5Encoder {
    
    public static String encode(String string) throws Exception {
        byte[] hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
        StringBuilder hex = new StringBuilder(hash.length * 2);
        for (byte b : hash) {
            if ((b & 0xFF) < 0x10) {
                hex.append("0");
            }
            hex.append(Integer.toHexString(b & 0xFF));
        }
        return hex.toString();
    }
}

 

posted @ 2016-11-14 14:31  ecollab  阅读(128)  评论(0编辑  收藏  举报