public static String md555(String plainText) throws UnsupportedEncodingException {
byte[] secretBytes = null;
try {
secretBytes = MessageDigest.getInstance("md5").digest(
plainText.getBytes());
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("没有md5这个算法!");
}
String md5code = new BigInteger(1, secretBytes).toString(16);// 16进制数字
// 如果生成数字未满32位,需要前面补0
for (int i = 0; i < 32 - md5code.length(); i++) {
md5code = "0" + md5code;
}
return md5code;
}

这里会出现的问题是字符串编码问题,如果不进行编码的话有可能会产生不一样的密文。这里只需要改成

plainText.getBytes(“utf-8”)就可以了。

相关文章:

  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2021-12-19
  • 2022-02-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
相关资源
相似解决方案