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

查看:85
本文介绍了将加密密钥存储在.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.

此安全文件必须解密在运行时和配置值读取。但是出现了一个问题,键和初始化向量在代码中被硬编码,因此任何人都可以使用反射器读取它。

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中存储加密密钥的最佳方法是什么?没有人可以使用Reflector读取它们?

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

推荐答案

如果你想保护你的数据从其他用户。请查看 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放在你的代码中。每次创建一个新的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天全站免登陆