.NET,BouncyCastle:如何保存公钥然后从文件导入它?
情况
您好,我正在我的 .NET 项目中使用充气城堡 API。 随机生成私钥和公钥
RsaKeyPairGenerator g = new RsaKeyPairGenerator();
g.Init(new KeyGenerationParameters(new SecureRandom(), 1024));
AsymmetricCipherKeyPair keys = g.GenerateKeyPair();
privateKey = keys.Private;
publicKey = keys.Public;
到目前为止,我可以使用我也可以加密/解密 byte[]
。 问题 如何将密钥保存到文件中?保存后如何导入它们?
Situation
Hi, I am using the bouncy castle API in my .NET project. Until now i can generate randomly the private and public keys using
RsaKeyPairGenerator g = new RsaKeyPairGenerator();
g.Init(new KeyGenerationParameters(new SecureRandom(), 1024));
AsymmetricCipherKeyPair keys = g.GenerateKeyPair();
privateKey = keys.Private;
publicKey = keys.Public;
I can encrypt/decrypt byte[]
as well.
Question
How can i save the keys into a File ? and how can I import them to after saving them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的代码项目的一部分:(谁将公钥保存到文件中)
var certif_dsa = new X509Certificate2(certificat_dsa, "password");
var pubkey_dsa = certif_dsa.GetPublicKeyString();
StreamWriter FluxInfos_dsa = null; // le fichier de la clé publique trouver le au debug
欲了解更多信息,请向我发送会话至 [电子邮件受保护]
this is a part of my code project: (who to save a public key into a file)
var certif_dsa = new X509Certificate2(certificat_dsa, "password");
var pubkey_dsa = certif_dsa.GetPublicKeyString();
StreamWriter fluxInfos_dsa = null; // le fichier de la clé publique trouver le au debug
for more information send me a sessage to [email protected]
您是否尝试过将应用程序配置文件添加到您的项目中?
它允许您轻松地以键/值格式(XML)保存运行时设置,
然后您可以在应用程序中创建一个配置管理器对象来保存和读取您的密钥;在你的情况下是 API 密钥
have you tried adding and app configuration file to your project?
It allows you to easily save runtime settings in a key/value format(XML)
you can then create a configurationmanager object in your app to save and read your keys; which in your case is the API key