zoukankan      html  css  js  c++  java
  • MD5加密

    1、MD5加密类

    import java.security.MessageDigest;

    /**  *  将编码格式改成  UTF-8   */

    public class Md5 {  

    private static final String encryModel = "MD5";

     /**   * md5加密方法   * @param str   * @return   */    

    public static String md5(String str) throws Exception {        

       return md5(encryModel, str.getBytes("utf-8"));    

    }

    public static String md5(String algorithm, byte[] data) {        

      try {            

        MessageDigest md = MessageDigest.getInstance(algorithm);            

        md.update(data);            

        StringBuffer sb = new StringBuffer();            

        byte[] bytes = md.digest();            

         for (int i = 0; i < bytes.length; i++) {                

            int b = bytes[i] & 0xFF;                

             if (b < 0x10) {                    

              sb.append('0');                

             }                

             sb.append(Integer.toHexString(b));            

         }            

         return sb.toString();        

       } catch (Exception e) {            

      return "";         }     }      }

    2、调用MD5对字符串进行加密

    Md5.md5("要加密的字符串"); 

  • 相关阅读:
    Codeforces 1316B String Modification
    Codeforces 1305C Kuroni and Impossible Calculation
    Codeforces 1305B Kuroni and Simple Strings
    Codeforces 1321D Navigation System
    Codeforces 1321C Remove Adjacent
    Codeforces 1321B Journey Planning
    Operating systems Chapter 6
    Operating systems Chapter 5
    Abandoned country HDU
    Computer HDU
  • 原文地址:https://www.cnblogs.com/Defry/p/4607062.html
Copyright © 2011-2022 走看看