BouncyCastle 从现有密钥创建 AsymmetryCipherKeyPair?

发布于 2024-09-09 17:05:48 字数 280 浏览 3 评论 0原文

我有两个 AssymetricAlgorithm RSA 密钥,它们是从我的密钥库中的证书中提取的。一个是公钥,另一个是私钥。有没有办法将此密钥对放入 BouncyCastle AsymmetryCipherKeyPair 中? BouncyCastle 的 AmetryCipherKeyPair 需要一个公共和私有的 AmetryKeyParameter,但是如果不是 AssymetricAlgorithm 的实例,我无法获取我的私钥。

I have two AssymetricAlgorithm 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两仪 2024-09-16 17:05:48

我认为如果密钥被标记为可导出,这会有所帮助

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文