zoukankan      html  css  js  c++  java
  • 工具类Md5加密方法

    package com.jyc.common.utils.sign;

    import java.security.MessageDigest;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;

    /**
    * Md5加密方法
    *
    * @author jianyongchao
    */
    public class Md5Utils
    {
    private static final Logger log = LoggerFactory.getLogger(Md5Utils.class);

    private static byte[] md5(String s)
    {
    MessageDigest algorithm;
    try
    {
    algorithm = MessageDigest.getInstance("MD5");
    algorithm.reset();
    algorithm.update(s.getBytes("UTF-8"));
    byte[] messageDigest = algorithm.digest();
    return messageDigest;
    }
    catch (Exception e)
    {
    log.error("MD5 Error...", e);
    }
    return null;
    }

    private static final String toHex(byte hash[])
    {
    if (hash == null)
    {
    return null;
    }
    StringBuffer buf = new StringBuffer(hash.length * 2);
    int i;

    for (i = 0; i < hash.length; i++)
    {
    if ((hash[i] & 0xff) < 0x10)
    {
    buf.append("0");
    }
    buf.append(Long.toString(hash[i] & 0xff, 16));
    }
    return buf.toString();
    }

    public static String hash(String s)
    {
    try
    {
    return new String(toHex(md5(s)).getBytes("UTF-8"), "UTF-8");
    }
    catch (Exception e)
    {
    log.error("not supported charset...{}", e);
    return s;
    }
    }
    }
  • 相关阅读:
    C++日记 OPENGL错误及解决方案
    C++日记 VS编译问题
    OpenGL 自制API 4
    C++日记 宏定义函数
    OpenGL 自制API gluPerspective
    OpenGL 自制API 3
    OpenGL 自制API 2
    OpenGL 自制API 1
    OPENGL入门教程
    c++基础的记录(随笔记录一些基础的东西)
  • 原文地址:https://www.cnblogs.com/qq3245792286/p/15470418.html
Copyright © 2011-2022 走看看