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() ;
	}
}
相关推荐
雪的季节4 分钟前
企业级 Qt 全功能项目
开发语言·数据库·qt
代龙涛1 小时前
WordPress page.php 页面模板与自定义模板使用方法
android·开发语言·php
bigfootyazi1 小时前
python爬虫-基本库-urllib库(常用速查)
开发语言·爬虫·python
belong_my_offer2 小时前
认识到精通函数
开发语言·python
guygg882 小时前
最大相关-最小冗余(mRMR)特征选择 MATLAB 实现
开发语言·matlab
郭涤生2 小时前
C++ 高性能编程最佳实践清单
开发语言·c++
烛衔溟2 小时前
TypeScript 类的静态成员与静态方法
开发语言·javascript·typescript
Nile2 小时前
解密Palantir系列一:4. Ontology 不是哲学
开发语言·前端·javascript
罗超驿3 小时前
15.JavaScript 函数与作用域完全指南:语法、参数、表达式与作用域链实战
开发语言·前端·javascript
.千余3 小时前
【C++】C++类与对象2:C++构造函数、运算符重载与流输入输出全面解析
c语言·开发语言·前端·c++·经验分享