当前位置:首页 > 开发 > Web前端 > 前端 > 正文

MD5加密

发表于: 2012-07-02   作者:cngolon   来源:转载   浏览:
摘要: package com.score.common.util; import java.security.MessageDigest; /** *//**  * @discription:A tool of Secutity by SCORE  * @author     :golon  * @time  &n

package com.score.common.util;


import java.security.MessageDigest;

/** *//**
 * @discription:A tool of Secutity by SCORE
 * @author     :golon
 * @time       :2009-1-25
 * @version    :1.0
 * @see        :no
 */
public class Security {
    private synchronized static byte[] encode(String origin,String code) {
        byte[] hash = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            hash = md.digest(origin.getBytes(code));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return hash;
    }

    public synchronized static String getPassword(String origin,String code) {
        String result = "";
        byte[] hash = Security.encode(origin,code);
        for (int i = 0; i < hash.length; i++) {
            int itemp = hash[i]&0xFF;
            if(itemp<16) result += "0";
            result += Integer.toString(itemp, 16).toLowerCase();
        }
        return result;
    }

    public synchronized static boolean isPassword(String origin, String result,String code) {
        if (Security.getPassword(origin,code).equals(result)) {
            return true;
        }
        return false;
    }
    public static void main(String[] args){
        String result = "";
        
        result = Security.getPassword("tjfae13021117501;1349933222","UTF-8");
        
        System.out.println(result.toLowerCase());
        
        
    }
}

MD5加密

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号