Java 使用MD5哈希密码时,在com.ibm.crypto.provider.MD5.engineUpdate上获取ArrayIndexOutOfBoundsException
我们正在尝试使用MD5算法散列用户密码,下面是我们的示例代码:Java 使用MD5哈希密码时,在com.ibm.crypto.provider.MD5.engineUpdate上获取ArrayIndexOutOfBoundsException,java,md5,password-hash,Java,Md5,Password Hash,我们正在尝试使用MD5算法散列用户密码,下面是我们的示例代码: import java.security.MessageDigest; public class EncodingUtil { private static MessageDigest digester = MessageDigest.getInstance("MD5"); public static String hashPassword(String input) { if (digester
import java.security.MessageDigest;
public class EncodingUtil {
private static MessageDigest digester = MessageDigest.getInstance("MD5");
public static String hashPassword(String input) {
if (digester != null) {
digester.reset();
digester.update(input.getBytes());
byte[] messageDigest = digester.digest();
StringBuffer hexString = new StringBuffer();
for (byte element : messageDigest) {
hexString.append(Integer.toHexString(0xFF & element));
}
return hexString.toString();
}
return input;
}
}
但在并发测试期间(5个同时用户)出现以下错误:
因此,我们在以下代码行中得到此错误:
digester.update(input.getBytes());
因此,基本上我们使用的是java.security.MessageDigest.update(),这是一个SPI,WebSphere中的具体实现是com.ibm.crypto.provider.MD5.engineUpdate,在这里我们有这个ArrayIndexOutOfBoundsException
我们正在IBMWebSphere8.5和Java8中运行我们的应用程序。我试图查找IBM是否存在与此[com.IBM.crypto.provider.MD5.engineUpdate()]相关的任何问题,但找不到任何详细信息。也无法找到任何解决方案来修复或绕过此问题。
MessageDigest
-您不能在线程之间共享单个静态实例。为每个线程创建一个新实例。@StuartLC,谢谢你的建议。我将尝试将MessageDigest的类级初始化移到方法级,看看问题是否得到解决。对于MessageDigest
digester.update(input.getBytes());