InvalidKeyException java.security.InvalidKeyException:没有安装的提供程序支持此密钥:(空)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了InvalidKeyException java.security.InvalidKeyException:没有安装的提供程序支持此密钥:(空),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2464字,纯文字阅读大概需要4分钟。
内容图文
![InvalidKeyException java.security.InvalidKeyException:没有安装的提供程序支持此密钥:(空)](/upload/InfoBanner/zyjiaocheng/680/7cdd37ea8a81461088e84bedec36b1f8.jpg)
我有两个类,一个是主类,另一个是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: No installed provider supports this key: (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不是二进制数据的容器.
>结果字符串strDecryptedText应该是局部变量,而不是成员变量.
内容总结
以上是互联网集市为您收集整理的InvalidKeyException java.security.InvalidKeyException:没有安装的提供程序支持此密钥:(空)全部内容,希望文章能够帮你解决InvalidKeyException java.security.InvalidKeyException:没有安装的提供程序支持此密钥:(空)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。