⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 md5.java

📁 题库管理系统,用最新的jsp技术开发的,里面有一些比较好的方法,希望与大家共享
💻 JAVA
字号:
/*
 * MD5.java
 *
 * Created on 2006年10月20日, 上午12:10
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package TiKuMS;
import java.security.*;
import java.util.*;
/**
 *
 * @author hp
 */
public class MD5 {
    
    /** Creates a new instance of MD5 */
     private String inStr;
    private MessageDigest md5;

    /** Creates a new instance of MD5 */
    public MD5(String inStr)
    {
        this.inStr = inStr;
        try
        {
           this.md5 = MessageDigest.getInstance("MD5");
        }
        catch (Exception e)
        {
           System.out.println(e.toString());
           e.printStackTrace();
        }
    }
    public String compute()
    {
        char[] charArray = this.inStr.toCharArray();

        byte[] byteArray = new byte[charArray.length];

        for (int i=0; i<charArray.length; i++)
           byteArray[i] = (byte) charArray[i];

        byte[] md5Bytes = this.md5.digest(byteArray);

        StringBuffer hexValue = new StringBuffer();

        for (int i=0; i<md5Bytes.length; i++)
        {
            int val = ((int) md5Bytes[i] ) & 0xff; 
            if (val < 16) hexValue.append("0");
                hexValue.append(Integer.toHexString(val));
        }

        return hexValue.toString();
     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -