存储在.NET C#加密密钥的最佳方法 [英] Best way to store encryption keys in .NET C#

查看:347
本文介绍了存储在.NET C#加密密钥的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用中有很多敏感的配置设置,我们存储在其中再次加密的XML文件。

In our application we have a lot of sensitive configuration settings, which we are storing in a xml file which is again encrypted.

这安全的文件在运行时和读取配置值进行解密。但问题出现了密钥和初始化向量是在code硬codeD,因此任何人都可以使用反射读取它。

This secure file has to be decrypted in runtime and the configuration values read. but an issue arises that the key and initialization vector is hardcoded in the code and hence anyone can read it using Reflector.

什么是储存在.NET中的加密密钥的最佳方法,所以没有人可以使用反射阅读?

What is the best way to store encryption keys in .NET so no one can read them using Reflector?

推荐答案

如果你想保护其他用户的数据。看看在<一个href=\"http://msdn.microsoft.com/en-us/library/system.security.cryptography.protecteddata.aspx\">ProtectedData类。

If you want to protect your data from other users. Take a look at the ProtectedData class.

(声明:保护您的数据创建一个拷贝保护方案不包括在这个答案)。

(Disclaimer: Protecting your data to create a copy protection scheme is not covered in this answer).

本类使用从Windows DPAPI,加密和解密的用户或计算机级别的数据。

This classes uses the DPAPI from Windows, to encrypt and decrypt data on user or machine level.

使用ProtectedData / DPAPI从处理键和保护自己的数据释放你。你也可以选择保护数据为当前用户。该数据可从不同的计算机来读取,由同一域的用户。

Using ProtectedData/DPAPI frees you from handling keys and securing the data yourself. And you can choose to protect the data for the current user. The data can be read from different computers, by the same domain users.

如果你想创建自己的密钥。您可以为每个用户/机器的关键,并存储在注册表中的此密钥。因为注册表可以抵押,只有当前用户可以读取钥匙回来。我知道注册表有恶业,但实际上是在存储这样的数据非常好。

If you want create your own key. You can create a key per user/machine, and store this key in the registry. Because the registry can be secured, only the current user can read the key back. I know the registry has bad karma, but is actually very good at storing data like this.

PS:不要将IV在code。创建一个新的IV每一次,并把它在数据面前。

PS: Do not put the IV in your code. Create a new IV every time, and put it in front of the data.

这篇关于存储在.NET C#加密密钥的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆