MD5 的加密 http://my.oschina.net/lijindou/blog/717003
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/** * Created by admin on 2016/7/21. */ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * 对外提供getMD5(String)方法 * * @author randyjia */ public class MD5 { public static String getMD5(String val) throws NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(val.getBytes()); byte[] m = md5.digest();//加密 return getString(m); } private static String getString(byte[] b) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < b.length; i++) { sb.append(b[i]); } return sb.toString(); } } |