MD5加密工具
2015-08-31 10:57
309 查看
import java.security.MessageDigest; /** * md5加密 * * @author sjf */ public class MD5Util { /** * 字符串MD5加密 * @param 待加密的字符串 * @return 加密后的字符串 */ public final static String encrypt(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; } } }
相关文章推荐
- oracle数据库基本数据类型
- 全国城市数据库plist文件和sqlite文件和json文件
- MyBatis
- 15问答为专业测试人员揭开“精准测试”的面纱
- IOS学习笔记 ---- 15/08/30之前
- 第一次作业
- 安装ASP.net mvc3 Installation failed with error code: (0x80070643), "安装时发生严重错误 "
- 工具——SVN常用命令
- LinuxUnix time时间戳的处理转换函数
- Git的使用二(第一次提交修改)仅限Mac亲测
- elasticsearch 并发控制
- Rational Rose Enterprise Edition 2003 安装破解步骤
- Android移动端短信验证码的实现
- [leetcode] 273.Integer to English Words
- django中实现图片的上传功能
- JavaScript学习笔记3-附录(Java的各类型数据在内存中分配情况详解)
- linux module加载
- SpringMVC
- C++中定义一个不能被继承的类
- C++ Primer 学习笔记与思考_10 类型转换易错处大总结