OA信用盘平台维护与Md5加密密码 加密字符串

public static String md5(String str) {OA信用盘平台维护【企 娥:217 1793 408】
String result = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = md.digest(str.getBytes());
result = converByteToString(bytes);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return result;
}
/**

  • Purpose:将byte数组写出为String
  • @author Hermanwang
  • @param bytes
  • @return
  • @return String
    */
    public static String converByteToString(byte[] bytes) {
    String result ="";
    for(int i=0; i<bytes.length ;i++){
    int temp = bytes[i] & 0xff;
    String temphex =Integer.toHexString(temp);
    if(temphex.length()<2){
    result += "0"+temphex;
    }else{
    result += temphex;
    }
    }
    return result;
    }

猜你喜欢

转载自blog.51cto.com/13914409/2156313