zoukankan      html  css  js  c++  java
  • MD5Util

    package com.cc.hkjc.util;

    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    public class MD5Util {
        private final static String[] strDigits = { "0", "1", "2", "3", "4", "5",
             "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
     public MD5Util() {
     }

     private static String byteToArrayString(byte bByte) {
         int iRet = bByte;
         if (iRet < 0) {
             iRet += 256;
         }
         int iD1 = iRet / 16;
         int iD2 = iRet % 16;
         return strDigits[iD1] + strDigits[iD2];
     }

     private static String byteToNum(byte bByte) {
         int iRet = bByte;
         System.out.println("iRet1=" + iRet);
         if (iRet < 0) {
             iRet += 256;
         }
         return String.valueOf(iRet);
     }

     private static String byteToString(byte[] bByte) {
         StringBuffer sBuffer = new StringBuffer();
         for (int i = 0; i < bByte.length; i++) {
             sBuffer.append(byteToArrayString(bByte[i]));
         }
         return sBuffer.toString();
     }

     public static String SetMD5(String strObj) {
         String resultString = null;
         try {
             resultString = new String(strObj);
             MessageDigest md = MessageDigest.getInstance("MD5");
             resultString = byteToString(md.digest(strObj.getBytes()));
         } catch (NoSuchAlgorithmException ex) {
             ex.printStackTrace();
         }
         return resultString;
     }

     public static void main(String[] args) {
         MD5Util getMD5 = new MD5Util();
         System.out.println(getMD5.SetMD5("123456"));
     }

    }

  • 相关阅读:
    D触发器深入详细介绍(zhuanzai)
    脉冲
    数字电路中时序
    嵌入式中对某一位清0或置1
    8本推荐阅读的UX书籍
    Hadoop之HDFS的Shell操作
    Hadoop之HDFS概述
    Hadoop之搭建完全分布式运行模式
    Hadoop之运行模式
    Hadoop之运行环境搭建
  • 原文地址:https://www.cnblogs.com/strive-study/p/5161755.html
Copyright © 2011-2022 走看看