zoukankan      html  css  js  c++  java
  • JAVA 笔记 MD5加密

           简单的MD5加密代码:

    package com.test.md5;

    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;

    public class MD5Parase {
        public static String autType="MD5";
        
        public static String hash(String data){
            try{
                return hash(data.getBytes("UTF-8"));
            }
            catch(Exception ex){
                return null;
            }
        }
        
        public static String hash(byte[] bytes){
            synchronized(autType.intern()){
                MessageDigest digest;
                try {
                    digest=MessageDigest.getInstance(autType);
                } catch (NoSuchAlgorithmException e) {
                    // TODO Auto-generated catch block
                    return null;
                }
                digest.update(bytes);
                return encodeHex(digest.digest());
            }        
        }
        
        private static String encodeHex(byte[]bytes){
            StringBuilder buf= new StringBuilder(bytes.length*2);
            int i;
            for(i=0;i<bytes.length;i++){
                if(((int) bytes[i] & 0xff)<0x10){
                    buf.append("0");
                }
                buf.append(Long.toString((int)bytes[i] & 0xff,16));
            }
            return buf.toString();
        }
        
    }
  • 相关阅读:
    172. Factorial Trailing Zeroes
    96. Unique Binary Search Trees
    95. Unique Binary Search Trees II
    91. Decode Ways
    LeetCode 328 奇偶链表
    LeetCode 72 编辑距离
    LeetCode 226 翻转二叉树
    LeetCode 79单词搜索
    LeetCode 198 打家劫舍
    LeetCode 504 七进制数
  • 原文地址:https://www.cnblogs.com/yjl49/p/2451546.html
Copyright © 2011-2022 走看看