Android(安卓)/ Java ------ Sha1 and Md5
16lz
2021-01-25
Java 通用 SHA1 and MD5 算法,改SHA1只需把
hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
改成:
hash = MessageDigest.getInstance("SHA1").digest(string.getBytes("UTF-8"));
然后再改改catch里的语句就OK
public static String md5(String string) { byte[] hash; try { hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8")); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Huh, MD5 should be supported?", e); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Huh, UTF-8 should be supported?", e); } StringBuilder hex = new StringBuilder(hash.length * 2); for (byte b : hash) { if ((b & 0xFF) < 0x10) hex.append("0"); hex.append(Integer.toHexString(b & 0xFF)); } return hex.toString();}
更多相关文章
- android sqlite 不存在插入,存在更新语句
- java算法之去重查找重复元素
- android sqlite查询数据表的字段与相关属性
- Android(安卓)MD5加密算法
- GreenDao深入使用
- java android(ios)通用aes加密解密
- Android下高斯模糊的算法和demo
- Android(安卓)Custom Dialog错误Unable to add window -- token
- java.lang.RuntimeException: setAudioSource failed异常处理