ASP.NET WEB.CONFIG敏感信息加密学习
今天,看到PETSHOP4.0里的WEB.CONFIG对数据库连接字符串加密,所以特意学习并记录下来。
.net 提供了 System.Configuration.RsaProtectedConfigurationProvider 。
首先配置WEB.CONFIG
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configProtectedData>
<providers>
<clear />
<add name="KeyProvider" type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" keyContainerName="Key" useMachineContainer="true" />
</providers>
</configProtectedData>
<connectionStrings>
<add name="SQL_Northwind" connectionString="Data Source=localhost;Initial Catalog=Northwind;User ID=sa;Password=sa;" />
</connectionStrings>
</configuration>
asp.net 提供了命令行的方式,对其加密,这里我也没有具体实例,就不讲啦。
我还是按照程序的方式,新建一个页面
执行下面的方法:
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.GetSection("connectionStrings");
if (section != null && !section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("KeyProvider");
config.Save();
}
方法执行后,WEB.CONFIG 文件应该有类似以下的代码出现:
<connectionStrings configProtectionProvider="KeyProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
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#">
<Encrypt
相关文档:
ASP.Net邮件发送类
本文转自:http://www.pcstu.com/program/Asp_net/sl/20070706/52523.html
说明:本文没有测试,但看起来似乎不能用于发送附件,如要发送附件,可参考:http://blog.csdn.net/lff642/archive/2008/07/15/2654346.aspx
using System;
using System.Text;
using System.IO;
using System.Net;
using ......
ASP.NET C# 生成静态页面简单方法
//源码是替换掉模板中的特征字符
string mbPath = Server.MapPath("template.html");
Encoding cod ......
Asp.net支持三种类型的cache
想写一个技术快速概述,可能写得太多了。技术概略的目的是以最快最简单的方式描述出技术要点,也是我希望的最有效率的知识传播方式。
1. 页面/控件cache
2. 应用程序级cache
3. 浏览器客户端cache
从实现方式来看,页面/控件cache和应用程序级cache都是存放在服务器内存里面的,随着内 ......
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
usin ......