zoukankan      html  css  js  c++  java
  • MD5Utils

    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    
    import com.yundaex.common.crypto.WrappedNoSuchAlgorithmException;
    
    
    public class MD5Utils {
    
        /**
         * md5加密方法
         * @param source     源字符串
         * @return             加密后的字符串
         * @throws NoSuchAlgorithmException
         */
        public static String md5(String source) {
            char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
            
            MessageDigest md = null;
            try {
                md = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException e) {
                throw new WrappedNoSuchAlgorithmException(e.getMessage());
            }
            md.update(source.getBytes());
            byte[] tmp = md.digest();
            char[] str = new char[16 * 2];
            
            int k = 0;
            for (int i = 0; i < 16; i++) {
                byte byte0 = tmp[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str);
        }
        
        
        
    }
  • 相关阅读:
    九九乘法表
    计算器实现
    分装的日期类
    杨辉三角
    99乘法表
    素数
    java输出100以内质数
    跳台阶
    Counting Sheep
    课上作业
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/7095186.html
Copyright © 2011-2022 走看看