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相关问答推荐

.NET发布的应用程序运行与开发不同的端口

获取Ef-Core集合的DeleteBehavior

.NET MAUI 的登录页面

如何判断属性设置器是否公开

SetupSet() 已过时.代替什么?

如何使用 C# 关键字作为属性名称?

是否有任何 x 次的 for 循环的更短/更简单的版本?

使用返回随机结果的函数进行单元测试

如何删除只读文件?

是否有用于 Windows / C# 开发的可嵌入 Webkit 组件?

如何创建只读依赖属性?

如何使用转储文件来诊断内存泄漏?

Int 到字节数组

当程序员说针对接口而不是对象的代码时,他们是什么意思?

如何禁用 Alt + F4 关闭表单?

使用 C# 设置全局热键

从 C# 中的字符串中删除最后一个字符.优雅的方式?

Environment.GetFolderPath(...CommonApplicationData) 在 Vista 上仍然返回C:\Documents and Settings\

我应该如何删除 DbSet 中的所有元素?

EF Core 添加迁移构建失败