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.

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

推荐答案

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).

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

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: Do not put the IV in your code. Create a new IV every time, and put it in front of the data.

.net相关问答推荐

从删除项目时重新索引的列表中删除项目的最佳算法是什么?

System.IO.Directory.Exists 在 LINQ 语句中失败,但在 foreach 循环中没有

将 Span 传递到函数时出现 F# 错误

是否有任何为 C# 编写的模糊搜索或字符串相似函数库?

异步总是 WaitingForActivation

在 C# DllImport 中使用 32 位或 64 位 dll

如何在 WPF 应用程序中使用 App.config 文件?

String 是原始类型吗?

我可以在没有两个查询的情况下通过布尔标准将 IEnumerable 一分为二吗?

如何使用配置转换删除 ConnectionString

使用 XmlSerializer 将空 xml 属性值反序列化为可为空的 int 属性

C#As的 VB.NET 类似功能

如何将 System.Type 转换为其可为空的版本?

监听依赖属性的变化

等待 Async Void 方法调用以进行单元测试

如何使用 EPPlus 设置 XLSX 单元格宽度?

判断对象列表是否包含具有特定值的属性

例外:不支持 URI 格式

在不使用while循环的情况下找到最里面的异常?

作者主签名的时间戳发现了一个建链问题:UntrustedRoot: self-signed certificate in certificate chain