• MD5 加密


    public class MD5 {
        /**
         * MD5 字符串加密
         *
         * @param plainText     待加密字符串
         * @param num           加密位数
         * @return              加密后字符串
         */
        public static String md5(String plainText, int num) throws NoSuchAlgorithmException {
    
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte b[] = md.digest();
            int i;
            StringBuilder buf = new StringBuilder("");
            for (byte aB : b) {
                i = aB;
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
    
            if (num == 32) {
                return buf.toString().toUpperCase();
            }
    
            return buf.toString().substring(8, 24).toUpperCase();
    
        }
    
        /**
         * MD5 字符串加密
         *
         * @param plainText     待加密字符串
         * @return              加密后字符串
         */
        public static String md5(String plainText) {
            String passwd = "";
            try {
                passwd =  md5(plainText, 32);
            } catch (Exception e) {
    
            }
            return passwd;
        }
    
    }

  • 相关阅读:
    Delphi程序结构
    SQL存储过程解密 Encrypted object is not transferable, and script can not be generated

    在河南呢
    还在河南,写随笔吧
    HAVING
    mIRC
    关于CAP理论
    开篇
    移动信息系统
  • 原文地址:https://www.cnblogs.com/hanjun0612/p/9779741.html
Copyright © 2020-2023  润新知