.Net学习笔记 - Web.config节点加密
2008-07-17 14:55
615 查看
machine.config中指出了asp.net内置的两种加密方式,如下
<configProtectedData defaultProvider="RsaProtectedConfigurationProvider">
<providers>
<add name="RsaProtectedConfigurationProvider" type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" description="Uses RsaCryptoServiceProvider to encrypt and decrypt" keyContainerName="NetFrameworkConfigurationKey" cspProviderName="" useMachineContainer="true" useOAEP="false" />
<add name="DataProtectionConfigurationProvider" type="System.Configuration.DpapiProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" description="Uses CryptProtectData and CryptUnProtectData Windows APIs to encrypt and decrypt" useMachineProtection="true" keyEntropy="" />
</providers>
</configProtectedData>
调用方法:在Visual Studio 2005 Command Prompt里面输入
aspnet_regiis -pef connectionStrings F:/WebSite -prov DataProtectionConfigurationProvider
注释:-pef 表示加密; -pdf表示解密.
connectionStrings 表示web.config文件中的节点名
F:/WebSite 表示站点路径
-prov DataProtectionConfigurationProvider表示采用何种方式加密(如果省略则表示使用machine.config中的默认配置defaultProvider)
-------------------------------------------------------------------------------------------------------
btw:如果需要在程序代码中加密字符串,可以使用System.Security.Cryptography中提供的一些类,例如SHA1CryptoServiceProvider,示例如下
UnicodeEncoding ue = new UnicodeEncoding();
byte[] byteMessage = ue.GetBytes( "abcde" );
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider( );
byte[] hashValue = sha1.ComputeHash( byteMessage );
string hashString = Convert.ToBase64String( hashValue );
<configProtectedData defaultProvider="RsaProtectedConfigurationProvider">
<providers>
<add name="RsaProtectedConfigurationProvider" type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" description="Uses RsaCryptoServiceProvider to encrypt and decrypt" keyContainerName="NetFrameworkConfigurationKey" cspProviderName="" useMachineContainer="true" useOAEP="false" />
<add name="DataProtectionConfigurationProvider" type="System.Configuration.DpapiProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" description="Uses CryptProtectData and CryptUnProtectData Windows APIs to encrypt and decrypt" useMachineProtection="true" keyEntropy="" />
</providers>
</configProtectedData>
调用方法:在Visual Studio 2005 Command Prompt里面输入
aspnet_regiis -pef connectionStrings F:/WebSite -prov DataProtectionConfigurationProvider
注释:-pef 表示加密; -pdf表示解密.
connectionStrings 表示web.config文件中的节点名
F:/WebSite 表示站点路径
-prov DataProtectionConfigurationProvider表示采用何种方式加密(如果省略则表示使用machine.config中的默认配置defaultProvider)
-------------------------------------------------------------------------------------------------------
btw:如果需要在程序代码中加密字符串,可以使用System.Security.Cryptography中提供的一些类,例如SHA1CryptoServiceProvider,示例如下
UnicodeEncoding ue = new UnicodeEncoding();
byte[] byteMessage = ue.GetBytes( "abcde" );
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider( );
byte[] hashValue = sha1.ComputeHash( byteMessage );
string hashString = Convert.ToBase64String( hashValue );
相关文章推荐
- .net学习笔记----WebConfig常用配置节点介绍
- .net学习笔记---webconfig的读与写
- web.config 中 healthMonitoring 节点元素的学习笔记
- [.Net学习笔记]webconfig的自定义配置
- C#基础之.NET环境下WebConfig的加密
- web.config 节点的加密
- ASP.NET Forum 学习笔记系列--Web.config
- 给web.config节点加密
- .Net 对webconfig进行加密解密
- .net 读取web.config中单个节点的方法
- Silverlight学习笔记(5)——读取宿主web.config
- ASP.NET温故而知新学习系列之网站安全技术—Web.config加密和解密(一)
- .net中web.config解密加密
- .net基础学习(四):ASP.NET的Web.Config文件中的元素
- asp.net web.config的学习笔记
- web 学习笔记5-DOM以及节点的操作
- 跨域学习笔记3--web.config设置之system.webServer 详细介绍,为网站设置默认文档
- 给web.config节点加密
- Silverlight学习笔记——读取宿主web.config
- Silverlight配置web.config连接sql server 2008(学习笔记)