首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

MD5生成讯息摘要

2013-12-30 
MD5生成消息摘要public class MD5Util {private static final String MD5 MD5private static final i

MD5生成消息摘要

public class MD5Util {        private static final String MD5 = "MD5";        private static final int THIRTY_TWO = 32;        private static final int SHIFT = 4;        private static final byte BYTE_F = 0xf;        private static final char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };    public static String genMD5(String str, String encoding) throws NoSuchAlgorithmException, UnsupportedEncodingException {        MessageDigest md = MessageDigest.getInstance(MD5);        md.update(str.getBytes(encoding));        byte[] digests = md.digest();        char[] chs = new char[THIRTY_TWO];        int p = 0;        for (int i = 0; i < digests.length; i++) {            byte digest = digests[i];            chs[p++] = hexChars[digest >>> SHIFT & BYTE_F];            chs[p++] = hexChars[digest & BYTE_F];        }        return new String(chs);    }}

热点排行