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

📄 messagedigestutil.java

📁 这是《Struts网络编程实例》一书zhogn 的源代码部分
💻 JAVA
字号:
package org.ithinking.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
//消息摘要的辅助类,提供了MD5和SHA-1两种摘要算法
public class MessageDigestUtil {

	private MessageDigest currentAlorithm=null;
	public static final String MD5="MD5";
	public static final String SHA1="SHA-1";
	public MessageDigestUtil(String method)
	{
		try
		{
		currentAlorithm=MessageDigest.getInstance(method);
		}
		catch(NoSuchAlgorithmException e)
		{
			e.printStackTrace();
			currentAlorithm=null;
		}
	}
	public byte[] computeDigest(byte[] b)
	{
		if(currentAlorithm==null)
			return null;
		currentAlorithm.reset();
		currentAlorithm.update(b);
		byte[] hash=currentAlorithm.digest();
		return hash;
	}
	public byte[] computeDigest(String s)
	{
		
		return computeDigest(s.getBytes());
	}
}

⌨️ 快捷键说明

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