码迷,mamicode.com
首页 > 其他好文 > 详细

MD5+salt 工具类

时间:2019-03-08 15:10:13      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:tin   return   ack   salt   java   pen   algorithm   exception   nts   

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Encrypt {
    private static String []hex = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
    private static String MD5init(String text) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte []bytes = md5.digest(text.getBytes("utf8"));
            StringBuffer sb = new StringBuffer();
            for(byte b : bytes) {
                int tmp = b;
                if(tmp < 0) tmp += 128;
                int index1 = tmp / 16;
                int index2 = tmp % 16;
                sb.append(hex[index1]).append(hex[index2]);
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String encrypt(String message) {
        return MD5init(MD5init(message+"draymonder")+"draymonder");
    }

}

MD5+salt 工具类

标签:tin   return   ack   salt   java   pen   algorithm   exception   nts   

原文地址:https://www.cnblogs.com/Draymonder/p/10495896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!