![](/img/trans.png)
[英]java.security.InvalidKeyException: No installed provider supports this key: (null) while verifying signed pdf
[英]InvalidKeyException java.security.InvalidKeyException: No installed provider supports this key: (null)
我有两个类,一个是主类,另一个是AES的实现。
但是,在我的AES类中,我有一个解密字符串的方法,但每当我运行它时,它都会产生异常
我的加密方法工作正常但我的解密方法不能按预期工作。
代码
private Cipher aesCipherForDecryption;
String strDecryptedText = new String();
public String decryptAES(final String ciphertext) {
try {
aesCipherForDecryption = Cipher.getInstance("AES/CBC/PKCS5PADDING");
aesCipherForDecryption.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iV));
byte[] byteDecryptedText = aesCipherForDecryption.doFinal(byteCipherText);
strDecryptedText = new String(byteDecryptedText);
} catch (IllegalBlockSizeException e) {
System.out.print("IllegalBlockSizeException " +e);
} catch (BadPaddingException e) {
System.out.print("BadPaddingException "+e);
} catch (NoSuchAlgorithmException e) {
System.out.print("NoSuchAlgorithmException "+ e);
} catch (NoSuchPaddingException e) {
System.out.print("NoSuchPaddingException "+e);
} catch (InvalidKeyException e) {
System.out.print("InvalidKeyException "+e);
} catch (InvalidAlgorithmParameterException e) {
System.out.print("InvalidAlgorithmParameterException "+e);
}
System.out.println("\nDecrypted Text message is " + strDecryptedText);
return strDecryptedText;
}
此方法输出的错误是
InvalidKeyException java.security.InvalidKeyException:没有安装的提供程序支持此键:(null)
更新#1:
所以我已经更新了以下代码
public String decryptAES(byte[] ciphertext) {
String strDecryptedText = new String();
try {
byte[] byteDecryptedText = aesCipherForDecryption.doFinal(ciphertext);
strDecryptedText = new String(byteDecryptedText);
} catch (IllegalBlockSizeException e) {
System.out.print("IllegalBlockSizeException "+e);
e.printStackTrace();
} catch (BadPaddingException e) {
System.out.print("BadPaddingException "+e);
e.printStackTrace();
}
System.out.println("\nDecrypted Text message is " + strDecryptedText);
return strDecryptedText;
}
在主要班级我有这条线
byte [] byteciphertext = ciphertext.getBytes();
只是将字符串转换为字节
这是对的吗? 我还在
IllegalBlockSizeException javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipherjavax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
有人可以帮我解决这个问题吗?
谢谢。
secretKey
显然是null.
其他问题:
cipherText
。 cipherText
应该是byte[],
而不是String
:cipher text是binary,而String
不是二进制数据的容器。 strDecryptedText
应该是局部变量,而不是成员变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.