c# - 加密 web.config 文件中的 <appSettings> 标签

标签 c# .net encryption key

我最近看到这篇文章,它描述了加密 web.config 文件中的 connectionString 标签的过程:

http://chiragrdarji.wordpress.com/2008/08/11/how-to-encrypt-connection-string-in-webconfig/

我使用相同的方法对包含我的加密 key 的 web.config 文件中的 appSettings 标记进行加密。

我的问题是,如果我将项目交给将在不同机器上运行它的其他人,他们是否能够使用反向过程来解密 web.config 中的 appSettings 标记文件使用 aspnet_regiis 工具?如果不是,该项目还能在他的机器上运行吗?

这就是我在代码中检索加密 key 的方式:

string block_size = ConfigurationManager.AppSettings["rgbIV"];
string encryption_key = ConfigurationManager.AppSettings["key"];

最佳答案

文档证实,根据加密提供商的不同,我可能是对的:

http://www.asp.net/web-forms/tutorials/data-access/advanced-data-access-scenarios/protecting-connection-strings-and-other-configuration-information-vb

Note: Since we are using the DPAPI provider, which uses keys specific to the computer, you must run aspnet_regiis.exe from the same machine from which the web pages are being served. For example, if you run this command line program from your local development machine and then upload the encrypted Web.config file to the production server, the production server will not be able to decrypt the connection string information since it was encrypted using keys specific to your development machine. The RSA provider does not have this limitation as it is possible to export the RSA keys to another machine.

因此对于 RSA,使用了一些 key - 如果没有这些 key ,第 3 方将拥有一团无用的数据。

关于c# - 加密 web.config 文件中的 <appSettings> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16122829/

相关文章:

c# - 动态文本框绑定(bind)

c# - 扩展 LINQ 的选项

c# - 使用正则表达式扫描 T-SQL 的对象依赖关系

C# .net 核心 Confluent.Kafka Avro 反序列化

c# - 在 .Net framework 2.0 中使用 .Net framework 3.5 功能

c# - 内部 .Net Framework 数据提供程序错误 1

c# - 在特定位置插入 XML 节点

php - 使用 PHP 加密和解密密码的最佳方法?

c# 如何加密 SQL Server 连接字符串?

c# - 对象已存在于 RSACryptoServiceProvider 中