• 标准MD5加密算法


    标准MD5加密算法:

    public class Md5 {
        public static String getMd5(String s) {
            char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                    'a', 'b', 'c', 'd', 'e', 'f' };
    
            try {
                byte[] strTemp = s.getBytes();
                MessageDigest mdTemp = MessageDigest.getInstance("md5");
                mdTemp.update(strTemp);
                byte[] md = mdTemp.digest();
                int j = md.length;
                char str[] = new char[j * 2];
                int k = 0;
                for (int i = 0; i < j; i++) {
                    byte byte0 = md[i];
                    str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                    str[k++] = hexDigits[byte0 & 0xf];
                }
                return new String(str);
            } catch (Exception e) {
                return null;
            }
        }
    
        /**
         * 标准MD5加密
         * 
         * @param inStr
         * @return
         * @throws Exception
         */
        public static String toMD5(String inStr) {
            StringBuffer sb = new StringBuffer();
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(inStr.getBytes());
                byte b[] = md.digest();
                int i;
                for (int offset = 0; offset < b.length; offset++) {
                    i = b[offset];
                    if (i < 0)
                        i += 256;
                    if (i < 16)
                        sb.append("0");
                    sb.append(Integer.toHexString(i));
                }
            } catch (Exception e) {
                return null;
                // e.printStackTrace();
            }
            return sb.toString().toUpperCase();
        }
    
        public static void main(String[] args) throws Exception {
            System.out.println(toMD5("MATICSOFT").toUpperCase());
            System.out.println(getMd5("MATICSOFT").toUpperCase());
        }
    }
  • 相关阅读:
    Redis
    Maven总结
    spring知识点总结
    网上好文搜集整理
    python 代码删除空目录
    plantUML使用指南
    python的基础操作
    八卦基础编程学习
    python历年入坑记录大全
    python实现的百度云自动下载
  • 原文地址:https://www.cnblogs.com/longshiyVip/p/5075610.html
Copyright © 2020-2023  润新知