在将字符串转换为加密格式时,我遇到了左侧缺少“00”的错误。
通常使用常用的 md5 方法,您不会在您的应用程序中找到错误。
因此,请使用字符串“sandeep”测试您的应用程序(我使用它是因为它的左侧有一个“00”)。
这个问题搞砸了我的时间,最后我从链接中找到了以下解决方案。
“我在左侧有 00 的 md5 字符串出错,即字符串“sandeep”转换为“DCF16D903E5890AABA465B0B1BA51F”而不是实际的“00DCF16D903E5890AABA465B0B1BA51F”
我最终采用了这种方法,它在我的应用程序中很有效。”
public static String md5(String inputString) {
try {
// Create MD5 Hash
MessageDigest msgDigest = java.security.MessageDigest.getInstance("MD5");
msgDigest.update(inputString.getBytes());
byte msgDigestBytes[] = msgDigest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < msgDigestBytes.length; i++) {
String h = Integer.toHexString(0xFF & msgDigestBytes[i]);
while (h.length() < 2)
h = "0" + h;
hexString.append(h);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
参考: http: //www.coderexception.com/CbHuB1uHPWxXUQXi/converting-string-to-md5-gives-add-number-of-digits