如何使用充气城堡解密pkcs8加密私钥? [英] How to decrypt a pkcs8 encrypted private key using bouncy castle?
问题描述
我正在尝试使用弹性城堡库解密pkcs8加密的私钥。我使用充气城堡提供的 PEMParser
解析了包含私钥的文件。我得到了 PKCS8EncryptedPrivateKeyInfo
对象。我无法从中获取 PrivateKeyInfo
对象。
尝试解密时遇到以下异常。
i am trying to decrypt a pkcs8 encrypted private key using bouncy castle library. I parsed the file containing the private key using PEMParser
provided by bouncy castle. I got PKCS8EncryptedPrivateKeyInfo
object. I am unable to get the PrivateKeyInfo
object from this.
I am getting the following exception while trying to decrypt.
org.bouncycastle.pkcs.PKCSException:无法读取加密的数据:1.2.840.113549.1.5.13不可用:没有此类提供者:1.2.840.113549.1.5.13
org.bouncycastle.pkcs.PKCSException: unable to read encrypted data: 1.2.840.113549.1.5.13 not available: No such provider: 1.2.840.113549.1.5.13
这是其中的代码我使用了
here is the code which I used
PEMParser parser = new PEMParser(br);
PKCS8EncryptedPrivateKeyInfo pair = (PKCS8EncryptedPrivateKeyInfo)parser.readObject();
JceOpenSSLPKCS8DecryptorProviderBuilder jce = new JceOpenSSLPKCS8DecryptorProviderBuilder();
jce.setProvider("1.2.840.113549.1.5.13");
InputDecryptorProvider decProv = jce.build(password.toCharArray());
PrivateKeyInfo info = pair.decryptPrivateKeyInfo(decProv);
推荐答案
您是否尝试过使用jce.setProvider( BC );而不是jce.setProvider( 1.2.840.113549.1.5.13);
Have you tried with jce.setProvider("BC"); instead of jce.setProvider("1.2.840.113549.1.5.13");
编辑以添加@PeterDettman提供的解决方案:
除了使用jce.setProvider( BC);还安装BC提供程序 bouncycastle.org/wiki/display/JA1/Provider+Installation
In addition to use jce.setProvider("BC"); also install the BC provider bouncycastle.org/wiki/display/JA1/Provider+Installation
这篇关于如何使用充气城堡解密pkcs8加密私钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!