开发者

BouncyCastle create AsymmetricCipherKeyPair from existing keys?

开发者 https://www.devze.com 2023-01-07 09:18 出处:网络
I have two AssymetricAlgorithm开发者_JAVA技巧 RSA keys that I have pulled out of a certificate that was in my keystore. One is the Public Key and the other the Private. Is there a way of getting this

I have two AssymetricAlgorithm开发者_JAVA技巧 RSA keys that I have pulled out of a certificate that was in my keystore. One is the Public Key and the other the Private. Is there a way of getting this keypair into a BouncyCastle AsymmetricCipherKeyPair? BouncyCastle's AsymmetricCipherKeyPair expects a public and private AsymmetricKeyParameter however I have no way of getting my Private key without it being an instance of AssymetricAlgorithm.


The answer to this lies here:

Get Private Key from BouncyCastle X509 Certificate? C#


I think this will help if key is marked as exportable

RSACryptoServiceProvider key = (RSACryptoServiceProvider)X509Certificate2object.PrivateKey;
RSAParameters rsaparam = key.ExportParameters(true);
AsymmetricCipherKeyPair keypair = DotNetUtilities.GetRsaKeyPair(rsaparam);
0

精彩评论

暂无评论...
验证码 换一张
取 消