简体   繁体   English

如何在C#中对生成的RSA私钥进行加密和解密

[英]How to encrypt generated RSA private key and decrypt in c#

I have seen articles regarding encrypt/decrypt data using Private/Public key. 我看过有关使用私钥/公钥加密/解密数据的文章。 All I want to do is to just encrypt a generated RSA private key already stored in a file. 我要做的只是加密已经存储在文件中的生成的RSA私钥。 I have been browsing widely to get an idea how it can be done but with no luck.I presume my question is rather an unusual one. 我一直在广泛浏览以了解如何完成它,但是没有运气。我想我的问题是一个不寻常的问题。 Please help! 请帮忙!

First, you need a *Key derivation function, to turn your password into a symmetric key which you can use to encrypt your private key. 首先,您需要*密钥派生功能,将密码转换成对称密钥,您可以使用该对称密钥来加密私钥。 If you solely use the .NET framework, you should use the Rfc2898DeriveBytes class for that. 如果仅使用.NET框架,则应使用Rfc2898DeriveBytes类。 If you are able to use BouncyCastle, then SCrypt would be preferred. 如果您能够使用BouncyCastle,则首选SCrypt

Then you can encrypt your key, prefreably using the AES algorithm. 然后,可以使用AES算法加密密钥。

Some usable code sample can be found in this answer 此答案中可以找到一些可用的代码示例

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

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