标签:algorithm i++ exception dig param mes hal style digest
import java.security.*; /** * 类型描述:MD5加密 * @version 1.0 */ public class MD5Gen { public MD5Gen() { } /** * MD5加密 * * @param src * @return */ public static String getMD5(String src) { try { MessageDigest m = MessageDigest.getInstance("MD5"); m.update(src.getBytes()); byte[] s=m.digest(); return bintoascii(s); } catch (NoSuchAlgorithmException ex) { return null; } } public static String bintoascii(byte[] bySourceByte) { int len, i; byte tb; char high, tmp, low; String result = new String(); len = bySourceByte.length; for (i = 0; i < len; i++) { tb = bySourceByte[i]; tmp = (char) ((tb >>> 4) & 0x000f); if (tmp >= 10) { high = (char) (‘a‘ + tmp - 10); } else { high = (char) (‘0‘ + tmp); } result += high; tmp = (char) (tb & 0x000f); if (tmp >= 10) { low = (char) (‘a‘ + tmp - 10); } else { low = (char) (‘0‘ + tmp); } result += low; } return result; } }
标签:algorithm i++ exception dig param mes hal style digest
原文地址:https://www.cnblogs.com/SmallStrange/p/10652847.html