zoukankan      html  css  js  c++  java
  • Md5加密

    加密算法

    package com.stylefeng.guns.core.util;
    
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    
    /**
     * MD5加密类(封装jdk自带的md5加密方法)
     *
     */
    public class MD5Util {
    
        public static String encrypt(String source) {
            return encodeMd5(source.getBytes());
        }
    
        private static String encodeMd5(byte[] source) {
            try {
                return encodeHex(MessageDigest.getInstance("MD5").digest(source));
            } catch (NoSuchAlgorithmException e) {
                throw new IllegalStateException(e.getMessage(), e);
            }
        }
    
        private static String encodeHex(byte[] bytes) {
            StringBuffer buffer = new StringBuffer(bytes.length * 2);
            for (int i = 0; i < bytes.length; i++) {
                if (((int) bytes[i] & 0xff) < 0x10)
                    buffer.append("0");
                buffer.append(Long.toString((int) bytes[i] & 0xff, 16));
            }
            return buffer.toString();
        }
    
        public static void main(String[] args) {
            System.out.println(encrypt("123456"));
        }
    }
    View Code
  • 相关阅读:
    最近几周的总结
    做游戏
    枚举 结构 .....
    抽象类
    面向对象过程
    构造函数 对象关系
    .net 第二周学习
    。net初学
    CSS基本知识点(01)
    C#之ADO.NET基本知识点(01)
  • 原文地址:https://www.cnblogs.com/JonaLin/p/11248256.html
Copyright © 2011-2022 走看看