MD5(3)
import java.io.UnsupportedEncodingException; import java.security.PrivateKey; import java.security.SignatureException; import org.apache.commons.codec.digest.DigestUtils; /** * MD5签名处理核心文件 * */ public class MD5 { /** * 签名字符串 * * @param text * 需要签名的字符串 * @param key * 密钥 * @param input_charset * 编码格式 * @return 签名结果 */ public static String sign(String text, String key, String charset) throws Exception { text = text + key; return DigestUtils.md5Hex(getContentBytes(text, charset)); } /** * 签名字符串 * * @param text * 需要签名的字符串 * @param key * 密钥 * @param input_charset * 编码格式 * @return 签名结果 * @deprecated 无替代方法 */ public static String sign(String text, PrivateKey key, String charset) throws Exception { throw new UnsupportedOperationException(); } /** * 签名字符串 * * @param text * 需要签名的字符串 * @param sign * 签名结果 * @param key * 密钥 * @param input_charset * 编码格式 * @return 签名结果 */ public static boolean verify(String text, String sign, String key, String charset) throws Exception { text = text + key; String mysign = DigestUtils.md5Hex(getContentBytes(text, charset)); if (mysign.equals(sign)) { return true; } else { return false; } } /** * @param content * @param charset * @return * @throws SignatureException * @throws UnsupportedEncodingException */ private static byte[] getContentBytes(String content, String charset) { if (charset == null || "".equals(charset)) { return content.getBytes(); } try { return content.getBytes(charset); } catch (UnsupportedEncodingException e) { throw new RuntimeException("签名过程中出现错误,指定的编码集不对,您目前指定的编码集是:" + charset); } } } |
最新文章
- php页面编码与字符操作
- 王总QQ聊天对话
- 樱花漫地集于我心,蝶舞纷飞祈愿相随---总结 适者:survival of the fittest 适者:survival of the fittest
- JQuery的Ajax跨域请求原理概述及实例
- RSA算法小记
- MD5加密算法
- hihoCoder:#1079(线段树+离散化)
- JedisPool连接池实现难点
- LNK1123: 转换到 COFF 期间失败: 文件无效或损坏[汇总]
- 关于tcc、tlink的编译链接机制的研究
- C库专题(Day1)
- Struts2详细说明
- java 打开浏览器 url
- JAVA课程设计-学生信息管理系统(个人博客)
- [ZJOI2007] 矩阵游戏
- python excel写入及追加写入
- linux服务器部署tomcat和Nginx
- centos6.5上安装redis3.2.1遇见的坑
- Delphi与各数据库数据类型比较
- noip第8课资料
热门文章
- mongodb驱动接口
- Rendering in UE4
- mysql技巧一则-避免重复插入相同数据
- django migrate报错:1005 - Can't create table xxx (errno: 150 ";Foreign key constraint is incorrectly formed";)
- object store in javascript
- forword动作
- 11-Flutter移动电商实战-首页_屏幕适配方案和制作
- .net core 多sdk 多版本 环境切换
- WinDbg常用命令系列---单步执行p*
- 集成omnibus-ctl+ chef 制作一个可配置的软件包