web文件加密

讲解以及源代码下载
ASP.NET 2.0: Encrypting Connection Strings

http://blogs.vertigosoftware.com/snyholm/archive/2005/12/16/1746.aspx

http://msdn2.microsoft.com/en-us/library/yxw286t2.aspx
中文
http://msdn2.microsoft.com/zh-cn/library/yxw286t2.aspx

ASP.NET 2.0: Encrypting Connection Strings

In ASP.NET 2.0, Microsoft added a handy utility for encrypting sensitive data in your web.config.  I used it to encrypt connection strings, but it could be used for nearly any section.  The familiar aspnet_regiis.exe utility is used to encrypt and decrypt the sections.  It creates key containers to store the encryption keys.  You use this utility differently depending on your environment.  The dev environment is the simplest to configure because you’re probably working with admin privileges on your box.  A single server environment is a little more complicated because you must give the website user account permission to the key container.  A web farm or multiple server environment involves the most steps because you must also create a .XML file to export the RSA encryption keys.

If you don’t know which account your website is running under, you can figure it out by temporarily add this code to a web page.
Response.Write("<BR><BR>The current identity is: " + System.Security.Principal.WindowsIdentity.GetCurrent().Name)
Response.Write("<BR><BR>The logged in user is: " + Page.User.Identity.Name.ToString())

We tested the performance in our lab with both a "real" application and with a simple application that just contained a single web page that calls a database.  Both applications maintained the same performance when using clear text and encrypted connection strings. 


Prepare your web.config for encryption:
1. Convert your connection strings to use the new <connectionStrings> section inside the <configuration> section.  Here is an example:
<connectionStrings> 
  <!-- SQL connection string for My Database -->
  <add name="MySQLConnString" connectionString="server=(local);user id=MyDBUser;password=A$tr0ng_Password;database=MyDatabaseName" providerName="System.Data.SqlClient"/>
</connectionStrings>

You can access connection strings from your code like this:
private string MyConnectionString = ConfigurationManager.ConnectionStrings["MySQLConnString"].ConnectionString;

2. Add this attribute to the configuration node in web.config:
<configuration xmlns=http://schemas.microsoft.com/.NetConfiguration/v2.0>

3. Add this section inside the <configuration> section:
<configProtectedData>
  <providers>
    <add name="MyProtectedDataProviderName"
         type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
         keyContainerName="MyKeyContainerName"
         useMachineContainer="true" />
  </providers>
</configProtectedData>
Note: The PublicKeyToken value is a constant value that is used by most of the framework, including System.Web and System.Configuration.


Note: Run the aspnet_regiis command from the <Windows>\Microsoft.NET\Framework\<version> folder (usually C:\Windows\Microsoft.NET\Framework\v2.0.50727). 

original.aspx

To encrypt connection strings on a development box:
1. To encrypt:
aspnet_regiis.exe -pef "connectionStrings" "C:\physical_location_of_my_web_app"

To decrypt:
aspnet_regiis.exe -pdf "connectionStrings" "C:\physical_location_of_my_web_app"

To encrypt connection strings on a single web server:

1. Prior to running the website, run these commands to create a key container and give the website user account permissions to use the key container.
aspnet_regiis -pc "MyKeyContainerName"
aspnet_regiis -pa "MyKeyContainerName" "NT AUTHORITY\NETWORK SERVICE"

2. Run this command to encrypt the <connectionStrings> section:
aspnet_regiis.exe -pef "connectionStrings" "C:\physical_location_of_my_web_app" -prov "MyProtectedDataProviderName"

To decrypt, run this command:
aspnet_regiis.exe -pdf "connectionStrings" "C:\physical_location_of_my_web_app"

To remove the key container, use this command:
aspnet_regiis -pz "MyKeyContainerName”

To encrypt connection strings on a web farm:
1. Create an exportable RSA encryption key.  The utility will put the file in this folder: \Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys.  The files have undecipherable names, but you can tell which is yours by the timestamp.
aspnet_regiis -pc "MyKeyContainerName" –exp

original.aspx

2. Create an .XML file for exporting this encryption key to your web servers.  Be careful not to overwrite your old file – it does not give you an "are you sure" prompt!
aspnet_regiis -px "MyKeyContainerName" "C:\MyFileName.xml" –pri

3. Encrypt the <connectionStrings> section.
aspnet_regiis -pe "connectionStrings" -app "/MyVirtualDirectory" -prov "MyProtectedDataProviderName"

4. Deploy the .XML file to a local directory on your web servers.

5. On your web servers, run the following commands to import the custom RSA encryption keys, create a key container and give the website user account permissions to use the key container.  Run these commands before using the encrypted web.config or else your application will throw this compilation error "Failed to decrypt using provider 'MyInsideProtectedDataProvider'. Error message from the provider: The RSA key container could not be opened."

aspnet_regiis -pi "MyKeyContainerName" "C:\MyFileName.xml"
aspnet_regiis -pa "MyKeyContainerName" "NT Authority\Network Service"

6. Deploy the application with the encrypted web.config file to your web servers.  At a minimum, copy the <configuration>, <connectionStrings>, and <configProtectedData> sections.

7. To make sure that no one can decrypt the Web.config files that are encrypted by RSA key container, delete the .XML file from the Web server.

To decrypt:
aspnet_regiis –pd "connectionStrings" –app "/MyVirtualDirectory"

To remove the key container, use this command:
aspnet_regiis -pz "MyKeyContainerName"

References

MSDN: Security Practices: ASP.NET 2.0 Security Practices at a Glance
MSDN2: Encrypting Configuration Information Using Protected Configuration
Mohamed Sharaf's Blog
IOpine
Swesecure.com (in Danish)

 

http://blogs.vertigosoftware.com/snyholm/archive/2006/06.aspx

转载于:https://www.cnblogs.com/Nina-piaoye/archive/2006/08/15/477103.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/412085.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java开发和android开发_浅谈Java开发和Android开发的不同

Java是具有多种用例的完整开发语言&#xff0c;包括Web开发&#xff0c;PC程序开发&#xff0c;嵌入式开发等。Android开发是面向手机应用&#xff0c;使用Java较多&#xff0c;还有常用的H5跨平台混合架构模式。一&#xff0c;UI界面开发不同1)Java Swing现在Java开发基本上都…

远程上传下载文件-Xftp5

Xftp5下载 链接&#xff1a;https://pan.baidu.com/s/1Wzso_Q7mPy5uGOUlripEWg 密码&#xff1a;xfx9 安装选择家庭版 由于21端口没有开&#xff0c;所以不能选FTP, 选择SFTP&#xff0c;22端口 用哪个用户登录机会自动到该用户的家目录 连接上出先乱码问题 属性 OK. 转载于:h…

java反射 pdf_java反射学习笔记整理.pdf

java反射学习笔记整理.pdf还剩15页未读&#xff0c;继续阅读下载文档到电脑&#xff0c;马上远离加班熬夜&#xff01;亲&#xff0c;很抱歉&#xff0c;此页已超出免费预览范围啦&#xff01;如果喜欢就下载吧&#xff0c;价低环保&#xff01;内容要点&#xff1a;Java 反射笔…

变态跳台阶

题目描述 一只青蛙一次可以跳上1级台阶&#xff0c;也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。题解 简要提炼思路&#xff1a; 1、有n个台阶&#xff0c;则每次可以跳1&#xff0c;2&#xff0c;3&#xff0c;&#xff0c;&#xff0c;n个…

Visual Basic .NET处理Excle表格全接触

Visual Basic .Net处理Excel表格机理和处理Word文档一样&#xff0c;也是通过互操作&#xff0c;引入COM组件来实现的&#xff0c;所以前提条件是运行本文中介绍的程序的计算机必须安装Office 2000中的Excel软件。如果计算机安装的Office 2000&#xff0c;那么这个COM组件就是M…

aspnet_UsersInRoles_GetUsersInRoles

ALTERPROCEDUREdbo.aspnet_UsersInRoles_GetUsersInRoles --查询某角色的用户ApplicationNameNVARCHAR(256), RoleNameNVARCHAR(256)ASBEGINDECLAREApplicationIdUNIQUEIDENTIFIERSELECTApplicationIdNULLSELECTApplicationIdApplicationId FROMaspnet_Applications WHERELO…

Jenkins二 安装gitlab及其使用

git --version 如果没有安装git直接源码安装即可&#xff0c;如果安装了先删除原来的git。 yum -y remove git先安装编译git需要的包。 yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel下载&安装 去gitlab官网 https://abou…

编程使用资源文件实现多语言页面(In Action)

需求&#xff1a;我们的ASP.NET站点需要提供多语言支持&#xff0c;考虑到我们使用的是ASP.NET2.0&#xff0c;我们可以利用资源文件来实现。 <?xml:namespace prefix o ns "urn:schemas-microsoft-com:office:office" />NOTE:这里我们使用编程的方法实现&a…

java final内存机制_Java中的内存处理机制和final、static、final static总结

装载自&#xff1a;http://blog.csdn.net/wqthaha/article/details/20923579Java程序运行在JVM上&#xff0c;可以把JVM理解成Java程序和操作系统之间的桥梁&#xff0c;JVM实现了Java的平台无关性&#xff0c;由此可见JVM的重要性。所以在学习Java内存分配原理的时候一定要牢记…

MySQL中的字符集涵义及使用方法总结(二)

五.乱码的避免最好让上述9个字符集变量值保持一致&#xff0c;或者至少“兼容”&#xff0c;同时也要考虑到OS中locale的值。当然&#xff1a;character_set_system例外&#xff0c;它是存储和表示元信息使用的字符集&#xff0c;一般都是ascii串&#xff0c;使用utf8和使用lat…

vim 多行添加注释,取消注释

转发 已经验证 https://blog.csdn.net/SuiXin_123/article/details/81393397转载于:https://www.cnblogs.com/pingg/p/10509301.html

调用未知DLL中的导出函数

不知道诸位看官是否有过这样的经历&#xff1a;在不经意之间发现一个DLL文件&#xff0c;它里边有不少有趣的导出函数——但是由于你不知道如何调用这些函数&#xff0c;所以只能大发感慨而又无能为力焉。固然有些知名的DLL可以直接通过搜索引擎来找到它的使用方式&#xff08;…

构建之法与博客首秀

问题一&#xff1a;软件的安全功能是指什么呢&#xff1f; 我看了《构建之法》第七页对飞机安全功能的的描述&#xff0c;想知道在软件中是否有类似飞机的安全功能&#xff1f;如果有&#xff0c;具体是指什么功能呢&#xff1f;我在查阅资料后只找到对软件安全的的总结(软件安…

java接口import_深入理解Java架构师在组件注册@Import导入容器(ImportSelector接口)的神操作!...

ImportSelector&#xff1a;返回需要导入的组件的全类名数组创建一个实现了ImportSelector接口的类&#xff0c;然后让入Import中。ImportSelector的实现类包含了所有需要导入到容器中的组件。public class StuConfigurationImportSerlect implements ImportSelector {Override…

java builder pool_每周10道Java面试题:String, String Pool, StringBuilder

每周10道 Java 面试题由 ImportNew 整理编译自网络。1. 写出下面代码的运行结果。int src 65536;Integer dst new Integer(65536);System.out.println(src dst);System.out.println(dst.equals(src));答案&#xff1a; true true考点&#xff1a; Integer 的 equals 实现。查…

将字符串中的字符按Z字形排列,按行输出

示例1&#xff1a; Input: s "PAYPALISHIRING", numRows 3 Output: "PAHNAPLSIIGYIR" 示例2&#xff1a; Python解决方案&#xff1a; def convert(self, s, numRows):""":type s: str:type numRows: int:rtype: str"""…

大型网络架构变迁和知识图谱

——仅供个人学习使用&#xff0c;如有侵犯版权&#xff0c;请作者联系我&#xff0c;立马处理。 【前端页面缓存】 sessionStorage,localStorage,userData,cookie, [sessionStorage] h5后出现的新技术&#xff0c;这个生命周期短&#xff0c;当页面关闭后&#xff0c;存储资源…

H265摄像头如何实现网页直播

介绍 目前安防监控行业&#xff0c;基本所有的摄像头都支持H264编码&#xff0c;但是已经有部分摄像头开始支持H265&#xff0c;并且支持H265的摄像机已经越来越多。H265相比H264有着很多优势&#xff0c;是压缩更高&#xff0c;网络传输消耗的带宽更小&#xff0c;相同码率下H…

【Python selenium自动化环境配置】4步搞定ChromeDriver版本选择

很多刚做自动化的小伙伴&#xff0c;会在ChromeDriver版本选择时犯难&#xff0c;看来大家都被坑过&#xff0c;真正掌握独门绝技&#xff0c;都不是难事儿。 看好了主要步骤就4部 1、确定谷歌浏览器版本 2、找到谷歌浏览器版本与ChromeDriver版本对应关系 3、下载ChromeDriver…

[贴图]TVB香港大部分演员照片、姓名(值得收藏)

转载于:https://www.cnblogs.com/chinhr/archive/2006/11/15/561101.html