MD5生成签名

java 复制代码
import java.nio.charset.Charset;
import java.security.MessageDigest;

public class MD5MsgDigest {

	public static string digest(string rawString) {
		return digest(rawString,"utf-8");
	}
	
	public static String digest(String rawStrinq, String charset) {
		Charset cs = Charset.forName (charset);
		try {
			return compute(rawstring, cs);
		} catch (Exception e) [
			return "";
		}
	}

	private static String compute(string inStr, Charset charset)throws Exception {
		MessageDigest md5 = MessageDigest.getInstance("MD5");
		byte[] md5Bytes = md5.digest(inStr.getBytes(charset));
		return toHexstring(md5Bytes);
	}
	
	public static String toHexstring(byte[] bytes) {
		StringBuffer hexValue = new StringBuffer();
		for (int i = 0; i < bytes.length; i++) {
			int val = ((int) bytes[i]) & Oxff;
			if (val < 16) {
				hexValue.append("0");
			}
			hexValue.append(Integer.toHexString(val));
		}
		return hexvalue.tostring() ;
	}
}
相关推荐
风吹迎面入袖凉1 分钟前
【Redis】Redisson分布式锁原理
java·服务器·开发语言
A.A呐2 分钟前
【QT第五章】系统相关
开发语言·qt
李白你好7 分钟前
Java GUI-未授权漏洞检测工具
java·开发语言
leo__52022 分钟前
拉丁超立方抽样(Latin Hypercube Sampling, LHS)MATLAB实现
开发语言·matlab
sycmancia24 分钟前
Qt——Qt中的标准对话框
开发语言·qt
橙露41 分钟前
Python 对接 API:自动化拉取、清洗、入库一站式教程
开发语言·python·自动化
Omigeq1 小时前
1.4 - 曲线生成轨迹优化算法(以BSpline和ReedsShepp为例) - Python运动规划库教程(Python Motion Planning)
开发语言·人工智能·python·算法·机器人
2301_808414381 小时前
自动化测试的实施
开发语言·python
波波0071 小时前
写出稳定C#系统的关键:不可变性思想解析
开发语言·c#·wpf
dr_yingli1 小时前
fMRI(3-1)报告(个体化报告)生成器说明
开发语言·matlab