java md5加密
2015-10-20 15:04
369 查看
public final static String MD5(String s) { char hexDigits[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; try { byte[] btInput = s.getBytes(); // 获得MD5摘要算法的 MessageDigest 对象 MessageDigest mdInst = MessageDigest.getInstance("MD5"); // 使用指定的字节更新摘要 mdInst.update(btInput); // 获得密文 byte[] md = mdInst.digest(); // 把密文转换成十六进制的字符串形式 int j = md.length; char str[] = new char[j * 2]; int k = 0; for (int i = 0; i < j; i++) { byte byte0 = md[i]; str[k++] = hexDigits[byte0 >>> 4 & 0xf]; str[k++] = hexDigits[byte0 & 0xf]; } return new String(str); } catch (Exception e) { e.printStackTrace(); return null; } }
相关文章推荐
- java 生成随机密码
- java list三种遍历方法性能比较
- hibernate4.0+springMVC+shoir时报错javax.persistence.OneToMany.orphanRemoval()Z
- spring mvc i18n设置
- Java中的值传递和引用传递
- 怎么在spring官网下载jar包问题
- Spring缓存注解@Cache使用
- java 读取文件 RandomAccessFile
- 开源BI报表及OLAP多维分析平台OPENI(二)—搭建Eclipse下的Openi开发环境
- JAVA - 类反射
- Java中Split函数的用法技巧
- 解决myeclipse项目中,多出的WebContent文件夹
- java 变长参数
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法
- Java虚拟运行机制
- java遍历hashMap、hashSet、Hashtable
- java mock-Mockito
- eclipse报这个错误org.eclipse.swt.SWTError: No more handles
- Spring Bean基本管理实例详解
- java提高篇(三十)-----Iterator