MD5加密

  1. public final static String MD5(String s) {  
  2.          //16进制下数字到字符的映射数组    
  3.         char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',  
  4.                 'a', 'b', 'c', 'd', 'e', 'f' };  
  5.         try {  
  6.             byte[] strTemp = s.getBytes();  
  7.             MessageDigest mdTemp = MessageDigest.getInstance("MD5");  
  8.             mdTemp.update(strTemp);  
  9.             byte[] md = mdTemp.digest();  
  10.             int j = md.length;  
  11.             char str[] = new char[j * 2];  
  12.             int k = 0;  
  13.             for (int i = 0; i < j; i++) {  
  14.                 byte byte0 = md[i];  
  15.                 str[k++] = hexDigits[byte0 >>> 4 & 0xf];  
  16.                 str[k++] = hexDigits[byte0 & 0xf];  
  17.             }  
  18.             return new String(str);  
  19.         } catch (Exception e) {  
  20.             // TODO: handle exception  
  21.             e.printStackTrace();  
  22.             return null;  
  23.         }  
  24.     }  

例如输入字符串是:123456

MD5加密之后是:e10adc3949ba59abbe56e057f20f883e

原文地址:https://www.cnblogs.com/shenqz/p/6961059.html