zoukankan      html  css  js  c++  java
  • Java MD5加密工具类

    import org.apache.commons.codec.digest.DigestUtils;
    
    /**
     * <p>
     * MD5加密工具类
     * <p/>
     *
     * @author Mr.Wang
     * @date 2020/12/14
     */
    public class MD5Util {
        public final static String md5key = "Ms2";
    
        /**
         * MD5方法
         *
         * @param text 明文
         * @return 密文
         * @throws Exception
         */
        public static String md5(String text) throws Exception {
            //加密后的字符串
            String encodeStr = DigestUtils.md5Hex(text);
            System.out.println("MD5加密后的字符串为:encodeStr=" + encodeStr);
            return encodeStr;
        }
    
        /**
         * MD5验证方法
         *
         * @param text 明文
         * @param md5  密文
         * @return true/false
         * @throws Exception
         */
        public static boolean verify(String text, String md5) throws Exception {
            //根据传入的密钥进行验证
            String md5Text = md5(text);
            if (md5Text.equalsIgnoreCase(md5)) {
                System.out.println("MD5验证通过");
                return true;
            }
            return false;
        }
    }
  • 相关阅读:
    Gym
    Gym
    Gym
    Gym
    Gym
    bzoj 2734: [HNOI2012]集合选数
    bzoj 1068: [SCOI2007]压缩
    HDU 2899 Strange fuction
    hihocoder #1142 : 三分·三分求极值
    HDU 2824 The Euler function
  • 原文地址:https://www.cnblogs.com/w1440199392/p/15201304.html
Copyright © 2011-2022 走看看