日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

web文件加密

發(fā)布時(shí)間:2023/12/9 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 web文件加密 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

講解以及源代碼下載
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).?

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

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

轉(zhuǎn)載于:https://www.cnblogs.com/Nina-piaoye/archive/2006/08/15/477103.html

總結(jié)

以上是生活随笔為你收集整理的web文件加密的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。