zoukankan      html  css  js  c++  java
  • Java实现MD5散列

    生成MD5值
    String str = "12345";
    MessageDigest digest =MessageDigest.getInstance("MD5");
    byte[] bs = digest.digest(str.getBytes());
    BytesPrint("未经过散列的S:",bs);
    String bb = "";
    for(int i =0;i<bs.length;i++)
    {
        bb += byteHEX(bs[i]);
    }
    System.out.println(bb);
    
    String aa = new String(bs, "iso-8859-1");//直接转化成字符串,省地
    打印出来  
     82 7c cb 0e ea 8a 70 6c 4c 34 a1 68 91 f8 4e 7b 
    static public void BytesPrint(String string, byte[] bs)
    {
        System.out.print(string);
        for (int i=0;i<bs.length;i++)
        {
            System.out.printf("%02x ",bs[i]);
        }
        System.out.println("");
    }
    生成字符串
    public static String byteHEX(byte ib)
    {
        char[] Digit ={ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        char[] ob = new char[2];
        ob[0] = Digit[(ib >>> 4) & 0X0F];
        ob[1] = Digit[ib & 0X0F];
        String s = new String(ob);
        return s;
    }

    参考:




  • 相关阅读:
    sql
    java常见异常
    call的用法及NodeList与Array的区别
    os模块
    random模块
    time模块
    序列化模块
    模块介绍
    内置函数
    匿名函数-lambda
  • 原文地址:https://www.cnblogs.com/MarmaladeCat/p/3dbfb8890866d20beaffe2c96825e6f9.html
Copyright © 2011-2022 走看看