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() ;
	}
}
相关推荐
阿豪只会阿巴2 分钟前
项目心得——发布者和订阅者问题解决思路
linux·开发语言·笔记·python·ubuntu·ros2
wjs20245 分钟前
Java 注释
开发语言
人道领域11 分钟前
JavaWeb从入门到进阶(javaScript)
开发语言·javascript·ecmascript
chilavert31820 分钟前
技术演进中的开发沉思-317 JVM:指令集(下)
开发语言·python
不绝19140 分钟前
C#核心——面向对象:封装
开发语言·javascript·c#
yaoxin5211231 小时前
294. Java Stream API - 对流进行归约
java·开发语言
ghie90901 小时前
基于MATLAB的演化博弈仿真实现
开发语言·matlab
曹轲恒1 小时前
Thread.sleep() 方法详解
java·开发语言
aini_lovee1 小时前
基于Qt实现CAN通信上位机
开发语言·qt
小小仙。1 小时前
IT自学第十九天
java·开发语言