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();}

更多相关文章

  1. android sqlite 不存在插入,存在更新语句
  2. java算法之去重查找重复元素
  3. android sqlite查询数据表的字段与相关属性
  4. Android(安卓)MD5加密算法
  5. GreenDao深入使用
  6. java android(ios)通用aes加密解密
  7. Android下高斯模糊的算法和demo
  8. Android(安卓)Custom Dialog错误Unable to add window -- token
  9. java.lang.RuntimeException: setAudioSource failed异常处理

随机推荐

  1. android ndk 安装
  2. android 串口编程
  3. android绘图网格线
  4. android jsonrpc 使用实例
  5. android API level
  6. android listview adater
  7. android:descendantFocusability 焦点 父
  8. Android(安卓)- How-to Rebuild gdbserve
  9. Android:Getting Started with Android(安
  10. Android强制联网