在运行时,解密密文时,使用Cipher获取java.lang.IllegalStateException未初始化的消息我的代码如下:
public String decrypt(String cipherText) throws SecurityException {
String clearText = null;
try {
cipher = Cipher.getInstance("AES/OFB/NoPadding");
byte[] cipherTextBytes = Base64.decodeBase64(cipherText.getBytes());
byte[] iv = ArrayUtils.subarray(cipherTextBytes, 0, INIT_VECTOR_LENGTH);
cipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv));
byte[] decryptedBytes = cipher
.doFinal(ArrayUtils.subarray(cipherTextBytes, INIT_VECTOR_LENGTH, cipherTextBytes.length));
clearText = new String(decryptedBytes, CHARACTER_ENCODING).trim();
} catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException | UnsupportedEncodingException
| NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException e) {
throw new SecurityException(e);
}
return clearText;
}
线程“ pool-5-thread-3”中的异常java.lang.IllegalStateException:密码未初始化在javax.crypto.Cipher.checkCipherState(Cipher.java:1749)在javax.crypto.Cipher.doFinal(Cipher.java:2156)
这是间歇性问题,经过一段时间后,它解密密文并按预期工作。