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() ;
	}
}
相关推荐
两点王爷3 小时前
Java 面试高频:JWT、Cookie、Session、Token 鉴权详解
java·开发语言·面试
微笑星河q5 小时前
C++高阶之【多态】
开发语言·c++
ClkLog-开源埋点用户分析8 小时前
【产品说明】【埋点分析】ClkLog 商业版 Java 运行环境安全更新说明
java·开发语言
yuzhiboyouye9 小时前
《阿里巴巴 Java 开发手册》的 MySQL 核心规范
java·开发语言·mysql
郝学胜-神的一滴9 小时前
Effective STL 条款12:对容器线程安全性的现实期望
c语言·开发语言·c++·qt·网络协议·rpc·numpy
geovindu10 小时前
python: KNeighborsClassifier K
开发语言·后端·python·算法
时间的情敌11 小时前
Three.js 射线拾取进阶:hover 高亮、点击弹窗、多物体过滤、穿透拾取
开发语言·javascript·three.js
Amumu1213812 小时前
TypeScript学习: 基本类型(一)
开发语言·前端·typescript
敲上瘾13 小时前
Qt 常用控件:按钮、显示输入、容器与布局等
开发语言·c++·qt·qt6.3