繁体   English   中英

如何在c#中使用bouncycastle将pem公钥转换为rsa公钥?

[英]how can i convert pem public key to rsa public key with bouncycastle in c#?

我有一个PEM 公共密钥,我想转换成XML格式的公共密钥或AsymmetricKeyParameter。

我可以PEM 私有密钥转换为公共/私人 XML格式或asymmetricKeyParameter与PemReader在BouncyCastle的在C#。但在使用时的Pem 公钥 PemReader,我收到错误。

请帮我。
我的问题还有什么解决方案?

这应该使用BouncyCastle做你想要的。

依赖关系:

using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Security;

从PEM转换为RSA XML格式的代码:

StreamReader reader = new StreamReader("yourPrivateKey.pem");
PemReader pemReader = new PemReader(reader);
AsymmetricCipherKeyPair keyPair = (AsymmetricCipherKeyPair)pemReader.ReadObject();
AsymmetricKeyParameter privateKey = keyPair.Private;
RSA rsa = DotNetUtilities.ToRSA((RsaPrivateCrtKeyParameters) privateKey);
string xmlRsa = rsa.ToXmlString(true);
Console.WriteLine(xmlRsa);

看看微软论坛中的这个条目浏览到Bell_Wang的回复,它指向一些为你进行转换的代码代码在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM