zoukankan      html  css  js  c++  java
  • Java Android 32位16位 MD5加密

    // md5加密 32位小写
    private String Md5(String sourceStr) {
    String result = "";
    try {
    MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(sourceStr.getBytes());
    byte b[] = md.digest();
    int i;
    StringBuffer buf = new StringBuffer("");
    for (int offset = 0; offset < b.length; offset++) {
    i = b[offset];
    if (i < 0)
    i += 256;
    if (i < 16)
    buf.append("0");
    buf.append(Integer.toHexString(i));
    }
    result = buf.toString();
     System.out.println("result: " + result);//32位的加密
     System.out.println("result: " +
     buf.toString().substring(8,24));//16位的加密
    } catch (NoSuchAlgorithmException e) {
    //TODO Auto-generated catch block e.printStackTrace();
    }
    return result;
    }
    

    记录一下,留着以后和需要的用吧,为以后节省点时间。

  • 相关阅读:
    线程
    自定义异常
    throw 子句
    throw 语句
    异常处理
    异常处理
    匿名类
    接口的使用,内部类
    接口,接口的定义
    如何理解无偏估计?无偏估计有什么用?什么是无偏估计?
  • 原文地址:https://www.cnblogs.com/xsgame/p/3447359.html
Copyright © 2011-2022 走看看