zoukankan      html  css  js  c++  java
  • MD5加密算法的Java实现

    import java.security.MessageDigest;
    import java.util.logging.Logger;
    
    /**
     * MD5加密算法
     */
    public class MD5 {
    
        public static String MD5(String key) {
            char hexDigits[] = {
                    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
            };
            try {
                byte[] btInput = key.getBytes();
                // 获得MD5摘要算法的 MessageDigest 对象
                MessageDigest mdInst = MessageDigest.getInstance("MD5");
                // 使用指定的字节更新摘要
                mdInst.update(btInput);
                // 获得密文
                byte[] md = mdInst.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;
            }
        }
    
        public static void main(String[] args){
    
            String MD5_String;
            MD5_String = MD5("weiqingde");
            System.out.println(MD5_String);
        }
    }
    

      

  • 相关阅读:
    git stash和git stash pop
    Ethereum HD Wallet(虚拟货币钱包)-BIP32、BIP39、BIP44
    bip44
    bip39
    bip32
    ethjs-1-了解
    myEtherWallet在线钱包的使用
    MetaMask/provider-engine-2-代码
    MetaMask/provider-engine-1
    MetaMask/eth-block-tracker
  • 原文地址:https://www.cnblogs.com/mr-hu2009/p/9457349.html
Copyright © 2011-2022 走看看