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 小时前
同城系统海外版:一站式多语种O2O系统源码
java·开发语言·git·mysql·uni-app·go·phpstorm
一只乔哇噻1 小时前
java后端工程师+AI大模型开发进修ing(研一版‖day60)
java·开发语言·人工智能·学习·语言模型
LNN20221 小时前
Linuxfb+Qt 输入设备踩坑记:解决 “节点存在却无法读取“ 问题
开发语言·qt
foxsen_xia2 小时前
go(基础06)——结构体取代类
开发语言·算法·golang
巨人张2 小时前
C++火柴人跑酷
开发语言·c++
ID_180079054732 小时前
基于 Python 的 Cdiscount 商品详情 API 调用与 JSON 核心字段解析(含多规格 SKU 提取)
开发语言·python·json
悟能不能悟2 小时前
Caused by: java.sql.SQLException: ORA-28000: the account is locked怎么处理
java·开发语言
亦是远方3 小时前
南京邮电大学使用计算机求解问题实验一(C语言简单编程练习)
c语言·开发语言·实验报告·南京邮电大学
我是哈哈hh3 小时前
【Python数据分析】Numpy总结
开发语言·python·数据挖掘·数据分析·numpy·python数据分析
Michelle80233 小时前
24大数据 14-2 函数练习
开发语言·python