zoukankan      html  css  js  c++  java
  • MD5进行加密操作

    package com.dyy.test;
    
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    
    public class TestMD5 {
    
        private final static String[] strDigits = { "0", "1", "2", "3", "4", "5",
                "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
    
        public TestMD5() {
        }
         
        public static void main(String[] args) {
            TestMD5 testMD5 = new TestMD5();
             System.out.println(testMD5.GetMD5Code("22"));
        }
    
        public static String GetMD5Code(String strObje) {
             String st = new String(strObje);
             try {
                MessageDigest digest = MessageDigest.getInstance("MD5");
                
                st = byteToString(digest.digest(strObje.getBytes()));
            } catch (NoSuchAlgorithmException e) {
                System.out.println("加密时报错");
                e.printStackTrace();
            }
            return st;
        }
    
        //转换字节数组为16进制字符
        private static String byteToString(byte[] digest) {
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < digest.length; i++) {
                buffer.append(byteToArrayString(digest[i]));
            }
            return buffer.toString();
        }
    
        private static Object byteToArrayString(byte b) {
             int br = b;
             
             if(br <0) {
                 br+=256;
             }
            int iD1 = br / 16;
            int iD2 = br % 16;
            return strDigits[iD1] + strDigits[iD2];
             
        }
        
        
        
        
        
    }
    当一个人在成长过程中,慢慢的享受学习,那么这个人就在成长,在往自己目标的方向奔跑.
  • 相关阅读:
    【转载】python_logging模块
    python安装模块速度慢的解决方法
    2020软件工程作业00
    2020软件工程个人作业——软件工程实践总结
    2020软件工程作业05
    2020软件工程作业04
    2020软件工程作业03
    2020软件工程作业02
    2020软件工程作业01
    列表、元组、集合和字典区别
  • 原文地址:https://www.cnblogs.com/zique/p/7496823.html
Copyright © 2011-2022 走看看