SHA1加密(简单)
生活随笔
收集整理的這篇文章主要介紹了
SHA1加密(简单)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
代碼:
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();}總結(jié)
以上是生活随笔為你收集整理的SHA1加密(简单)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MD5加密(简单)
- 下一篇: Map转xml格式字符串