ASP.NET 2.0加密Web.config 配置文件
|
源代码网整理以下 可以使用受保护配置来加密 Web 应用程序配置文件(如 Web.config 文件)中的敏感信息(包括用户名和密码、数据库连接字符串和加密密钥)。对配置信息进行加密后,即使攻击者获取了对配置文件的访问,也可以使攻击者难以获取对敏感信息的访问,从而改进应用程序的安全性。 源代码网整理以下<configuration> 源代码网整理以下 <connectionStrings> 软件开发网 www.mscto.com 源代码网整理以下 <add name="SampleSqlServer" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;" /> 源代码网整理以下 </connectionStrings> 源代码网整理以下</configuration> 源代码网整理以下 ASP.NET 2.0 中有一个新的安全特性.可以对 Web.config 文件中的任何配置节进行加密处理,可以通过手工运行工具aspnet_regiis或者编程来完成这个工作。如果你可以直接访问你的Web 服务器,你可以通过运行如下的命令行: 源代码网整理以下 cd %windows%Microsoft.NETFrameworkversionNumber 源代码网整理以下aspnet_regiis -pe "connectionStrings" -app "/SampleApplication" –prov RsaProtectedConfigurationProvider 源代码网整理以下-pd section 源代码网整理以下 对配置节进行解密。此参数采用下面的可选参数: 源代码网整理以下· -app virtualPath 指定应该在包含路径的级别进行解密。 源代码网整理以下· -location subPath 指定要解密的子目录。 源代码网整理以下· -pkm 指定应该对 Machine.config 而非 Web.config 文件进行解密。 源代码网整理以下-pdf section webApplicationDirectory 源代码网整理以下 对指定物理(非虚拟)目录中的 Web.config 文件的指定配置节进行解密。 源代码网整理以下-pe section 源代码网整理以下对指定的配置节进行加密。此参数采用下面的可选修饰符: 源代码网整理以下· -prov provider 指定要使用的加密提供程序。 源代码网整理以下· -app virtualPath 指定应该在包含路径的级别进行加密。 源代码网整理以下· -location subPath 指定要加密的子目录。 软件开发网 www.mscto.com 源代码网整理以下· -pkm 指定应该对 Machine.config 而非 Web.config 文件进行加密。 源代码网整理以下-pef section webApplicationDirectory 源代码网整理以下 对指定物理(非虚拟)目录中的 Web.config 文件的指定配置节进行加密。 源代码网整理以下 如果你是使用虚拟主机等不能访问物理的服务器,你仍然能够通过编程方式加密的连接字符串: 源代码网整理以下1 Configuration config = Configuration.GetWebConfiguration(Request.ApplicationPath); 源代码网整理以下2 ConfigurationSection section = config.Sections["connectionStrings"]; 源代码网整理以下3 section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");; 源代码网整理以下4 config.Update (); 源代码网整理以下 现在, 使用受保护配置对连接字符串值进行加密的配置文件不以明文形式显示连接字符串,而是以加密形式存储它们,如下面的示例所示: 源代码网整理以下<configuration> 源代码网整理以下 <connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider"> 软件开发网 www.mscto.com
源代码网整理以下 <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" 软件开发网 www.mscto.com 源代码网整理以下 xmlns="http://www.w3.org/2001/04/xmlenc#"> 源代码网整理以下 <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" /> 源代码网整理以下 <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> 源代码网整理以下 <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"> 源代码网整理以下 <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /> 软件开发网 www.mscto.com 源代码网整理以下 <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> 软件开发网 www.mscto.com 源代码网整理以下 <KeyName>RSA Key</KeyName> 源代码网整理以下 </KeyInfo> 源代码网整理以下 <CipherData> 源代码网整理以下<CipherValue>RXO/zmmy3sR0iOJoF4ooxkFxwelVYpT0riwP2mYpR3FU+r6BPfvsqb384pohivkyNY7Dm4lPgR2bE9F 源代码网整理以下i3N572qxdfmGfQc7ZbwNE= 源代码网整理以下 </CipherValue> 软件开发网 www.mscto.com
源代码网整理以下 </CipherData> 源代码网整理以下 </EncryptedKey> 源代码网整理以下 </KeyInfo> 源代码网整理以下 <CipherData> 源代码网整理以下 <CipherValue>KMNKBuV9nOid8pUvdNLY5I8R7BaEGncjkwYgshW8ClKjrXSM7zeIRmAy/cTaniu8Rfk92KVkEK83 源代码网整理以下11i+StkBLlHPyyhbnCAsXdz5CaqVuG0obEy2xmnGQ6G3Mzr74j4ifxnyvRq7levA2sBR4lhE5M80Cd5yKEJktcPWZYM 源代码网整理以下ZMfp4vOaqzKrSkHPie3zIR7SuVUeYPFZbcV65BKCUlT4EtPLgi8CHu8bMBQkdWxOnQEIBeY+TerAee/SiBCrA8M/n 源代码网整理以下MT1hB1SZjd8dmPgtZUyzcL51DoChy+hZ4vLzE= 源代码网整理以下 </CipherValue> 软件开发网 www.mscto.com 源代码网整理以下 </CipherData> 源代码网整理以下 </EncryptedData> 源代码网整理以下 </connectionStrings> 源代码网推荐 源代码网供稿. |
