计算字符串MD5值简单实现
2012-01-04 11:12
197 查看
public class Md5Util { /** * 取得字符串的MD5值 * * @param str * @return */ public static String getMd5(String str) { char[] charArray = str.toCharArray(); byte[] byteArray = new byte[charArray.length]; for (int i = 0; i < charArray.length; i++) byteArray[i] = (byte) charArray[i]; byte[] md5Bytes = null; try { md5Bytes = MessageDigest.getInstance("MD5").digest(byteArray); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } StringBuffer hexValue = new StringBuffer(); for (int i = 0; i < md5Bytes.length; i++) { int val = ((int) md5Bytes[i]) & 0xff; if (val < 16) { hexValue.append("0"); } hexValue.append(Integer.toHexString(val)); } return hexValue.toString(); } }
相关文章推荐
- 用简单的VBA实现Excel表格计算
- 【算法数据结构Java实现】递归的简单剖析及时间复杂度计算
- C#使用TimeSpan时间计算的简单实现
- 一个基于约束传播的,玩具级微型计算语言的设计和简单实现
- 用原生JS实现一个简单计算的功能实例
- vue实现简单实时汇率计算功能
- TensorFlow入门,基本介绍,基本概念,计算图,pip安装,helloworld示例,实现简单的神经网络
- Java实现简单的表达式计算
- 一个mfc实现的简单计算功能
- JS根据生日月份和日期计算星座的简单实现方法
- 实现一个简单的数学计算题
- 机房重构利用策略模式+简单工厂实现消费金额的计算
- 【并行计算】使用MPI实现简单的并行素数筛法
- JavaScript实现的超简单计算器功能示例
- C语言简单实现计算字符个数的方法
- 一个简单的jQuery计算器实现了连续计算功能
- 简单计算类--可实现字符串读入
- 实现下一秒日期计算(简单的时钟)。
- 赛码网,简单计算,用C语言自己实现的一个程序,仅供参考