MD5和SHA加密
来源:互联网 发布:delphi算法与数据结构 编辑:程序博客网 时间:2024/05/16 09:11
//MD5加密字符串32位 16位截取8-24 public static String md5Encode(String inStr) throws Exception { MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); return ""; } byte[] byteArray = inStr.getBytes("UTF-8"); byte[] md5Bytes = md5.digest(byteArray); 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(); } /*** * SHA加密 生成40位SHA码 * @param 待加密字符串 * @return 返回40位SHA码 */ public static String shaEncode(String inStr) throws Exception { MessageDigest sha = null; try { sha = MessageDigest.getInstance("SHA"); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); return ""; } byte[] byteArray = inStr.getBytes("UTF-8"); byte[] md5Bytes = sha.digest(byteArray); 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(); }
0 0
- MD5和SHA加密
- MD5和SHA加密
- 用户密码MD5和SHA加密
- md5加密和sha加密的使用
- iOS MD5加密和SHA-1加密
- 实现MD5和SHA加密的类
- IOS md5 和 sha哈希加密
- java中MD5和SHA加密
- 使用MD5和SHA算法加密信息
- MD5/SHA 加密处理
- MD5+SHA+BASE64加密
- 加密之SHA,MD5
- android md5加密和sha-1加密方法
- MD5加密与SHA加密
- Java单向(非可逆)加密--MD5、SHA和HMAC
- 如何使用MD5和SHA算法加密信息
- JAVA 常用的加密算法之单向加密MD5和SHA
- SHA 加密是什么( sha1 和 MD5 的区别 )
- WEB压测工具siege用法
- SIP中603/decline中的意义
- springMVC +mybatis的配置
- nginx配置备忘
- 好的开始,“first blood”
- MD5和SHA加密
- Linux epoll详解
- linux 配置开机自启动
- php获取http post raw
- linux下svn常用指令
- 8VC Venture Cup 2016 -C - Block Towers-二分
- 分类器评价、混淆矩阵与ROC曲线
- HTTP协议
- hibernate配置文件hibernate.cfg.xml安全线程的session配置