BouncyCastle的PrivateKey要X509Certificate2 PrivateKey

编程入门 行业动态 更新时间:2024-10-23 13:32:48
本文介绍了BouncyCastle的PrivateKey要X509Certificate2 PrivateKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建使用BouncyCastle的证书

I create a certificate using BouncyCastle

var keypairgen = new RsaKeyPairGenerator(); keypairgen.Init(new KeyGenerationParameters(new SecureRandom(new CryptoApiRandomGenerator()), 1024)); var keypair = keypairgen.GenerateKeyPair(); var gen = new X509V3CertificateGenerator(); var CN = new X509Name("CN=" + certName); var SN = BigInteger.ProbablePrime(120, new Random()); gen.SetSerialNumber(SN); gen.SetSubjectDN(CN); gen.SetIssuerDN(CN); gen.SetNotAfter(DateTime.Now.AddYears(1)); gen.SetNotBefore(DateTime.Now.Subtract(new TimeSpan(7,0,0,0))); gen.SetSignatureAlgorithm("MD5WithRSA"); gen.SetPublicKey(keypair.Public); gen.AddExtension( X509Extensions.AuthorityKeyIdentifier.Id, false, new AuthorityKeyIdentifier( SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keypair.Public), new GeneralNames(new GeneralName(CN)), SN )); gen.AddExtension( X509Extensions.ExtendedKeyUsage.Id, false, new ExtendedKeyUsage(new ArrayList() { new DerObjectIdentifier("1.3.6.1.5.5.7.3.1") })); var newCert = gen.Generate(keypair.Private);

本月底与

X509Certificate2 certificate = new X509Certificate2(DotNetUtilities.ToX509Certificate((Org.BouncyCastle.X509.X509Certificate)newCert));

现在,因为我的任务告诉我,来存储证书和PrivateKey在我需要一种方法来转换keypair.Private成X509Certificate2.Private的X509Certificate2对象。任何想法?

Now, because my assignment tells me to store both the Certificate and the PrivateKey in the X509Certificate2 object I need a way to convert the keypair.Private into a X509Certificate2.Private. Any ideas?

感谢。

推荐答案

如果你从this问题,你应该能够使用类似的东西来 DotNetUtilities.ToRSA(...)键,把它的返回值到 X509Certificate2 的 PrivateKey 。

If you look at the links from this question, you should be able to use something similar to DotNetUtilities.ToRSA(...) and put its return value into the X509Certificate2's PrivateKey.

更多推荐

BouncyCastle的PrivateKey要X509Certificate2 PrivateKey

本文发布于:2023-11-05 08:25:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560359.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:BouncyCastle   PrivateKey

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!