java md5工具类分享_技术学院_宜昌市隼壹珍商贸有限公司

您好,欢迎访问宜昌市隼壹珍商贸有限公司

400 890 5375
当前位置: 主页 > 新闻动态 > 技术学院

java md5工具类分享

发布时间:2026-01-17  |  点击率:

复制代码 代码如下:
import javasecurityMessageDigest;
import javasecurityNoSuchAlgorithmException;

/**
 * MD5工具类 
 *  
 * @author
 * @version 0 
 */ 
public class Md5Util {
    /** 
     * Md 
     * 
     * @param value the value 
     * @return the string 
     */ 
    public static String md5(String value) {  
        try {  
            MessageDigest md = MessageDigestgetInstance("md5");  
            byte[] e = mddigest(valuegetBytes());  
            return toHex(e);  
        }  
        catch (NoSuchAlgorithmException e) {  
            eprintStackTrace();  
            return value;  
        }  
    }  

    /** 
     * Md 
     * 
     * @param bytes the bytes 
     * @return the string 
     */ 
    public static String md5(byte[] bytes){
        try {  
            MessageDigest md = MessageDigestgetInstance("md5");  
            byte[] e = mddigest(bytes);  
            return toHex(e);  
        }  
        catch (NoSuchAlgorithmException e) {  
            e.printStackTrace();  
            return "";  
        }  
    }  

    /** 
     * To hex 
     * 
     * @param bytes the bytes 
     * @return the string 
     */ 
    private static String toHex(byte bytes[]){
        StringBuilder hs = new StringBuilder();  
        String stmp ="";
        for (int n = 0; n < byteslength; n++) {  
            stmp = IntegertoHexString(bytes[n] & 0xff);  
            if (stmplength() == 1)  
                hsappend("0")append(stmp);  
            else 
                hsappend(stmp);  
        }  
        return hstoString();  
    }  
}

全国统一服务电话

400 890 5375

电子邮箱:879577@qq.com

公司地址:宜昌市西陵区黄河路5号三峡明珠10栋1051室

咨询微信

TEL:13680874598