如何仅基于 RSA 格式的公钥生成 x509Certificate?

发布于 2024-12-15 21:00:48 字数 796 浏览 1 评论 0原文

我有一个 XML 格式的 RSA 公钥。我需要获取此密钥并使用该公钥创建 x.509 证书。我无权访问私钥来完成密钥对。我发现的所有示例都涉及生成密钥对或访问公钥和私钥。

下面是我为实现这一目标而一直致力于的测试例程的一小段。

RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
        provider.FromXmlString("<RSAKeyValue><Modulus>puEVvRbrLAz.......c1W5j/vqJSUrXo16k=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>");

       Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters key = Org.BouncyCastle.Security.DotNetUtilities.GetRsaPublicKey(provider);

//<!*** Do some code to take RsaKeyParameters and create an x.509 Certificate ***>

        var fOut = new System.IO.StreamWriter(@"C:\certificate.pem", false);
        var pw = new Org.BouncyCastle.OpenSsl.PemWriter(fOut);
        pw.WriteObject(key);

I have an RSA public key in an XML format. I need to take this key and create an x.509 Certificate using that public key. I do not have access to the private key to complete the key pair. All examples that I have found involve either generating the key pair or having access to both the public and private keys.

Below is a small snippet from a test routine I have been working on to accomplish this.

RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
        provider.FromXmlString("<RSAKeyValue><Modulus>puEVvRbrLAz.......c1W5j/vqJSUrXo16k=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>");

       Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters key = Org.BouncyCastle.Security.DotNetUtilities.GetRsaPublicKey(provider);

//<!*** Do some code to take RsaKeyParameters and create an x.509 Certificate ***>

        var fOut = new System.IO.StreamWriter(@"C:\certificate.pem", false);
        var pw = new Org.BouncyCastle.OpenSsl.PemWriter(fOut);
        pw.WriteObject(key);

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

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

发布评论

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

评论(1

琉璃繁缕 2024-12-22 21:00:48

只是为了澄清无法仅使用公钥生成证书的问题。

AFAIK,证书必须签名。并且必须使用私钥来完成 - 这就是为什么您需要一个私钥来生成证书。如果证书是使用您要为其颁发证书的开放密钥的配对私钥进行签名的,则它是自签名证书。否则,您需要所谓的证书颁发机构的私钥进行签名。

Just to clarify the issue of impossibility of generating a certificate using a public key only.

AFAIK, certificate must be signed. And it must be done with a private key - that's why you need one for generating a certificate. If certificate is signed with the paired private key of the open key you are going to issue a certificate for, than it is a self-signed certificate. Otherwise you need a private key of so called Certificate Authority for signing.

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