導航:首頁 > 文檔加密 > gs5加密封條

gs5加密封條

發布時間:2022-07-11 22:12:59

1. 如何為配置文件加密

在web.config或app.config文件里我們經常會存儲一些敏感信息,比如connectionStrings或者appSettings,比如像下面的文件。
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="MyNwConnectionString" connectionString="Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;"/>
</connectionStrings>
<appSettings>
<add key="User" value="myUsername"/>
<add key="Password" value="myPassword"/>
</appSettings>
</configuration>
using System;
using System.Configuration;

namespace WebConfigEncryptTest
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string user = ConfigurationManager.AppSettings.Get("User");
string password = ConfigurationManager.AppSettings.Get("Password");
string connectionString = ConfigurationManager.ConnectionStrings["MyNwConnectionString"].ConnectionString;
}
}
}

(一)加密文件可以使用的Provider
.NET為我們提供了一個工具aspnet_regiis.exe來對web.config文件中的敏感信息進行加密(app.config文件可以先改名為web.config,加密後再改回app.config)。你可以使用兩個provider中的一個來進行加密:
System.Configuration.:在System.Configuration.dll中,使用Windows DPAPI(Data Protection API)來進行加密,密鑰存在Windows Local Security Authority(LSA)中。注意:當使用時,加密文件所使用的帳號需要與運行web application的帳號相同,否則web application無法解密加密的內容。
System.Configuration.:在System.Configuration.dll中,使用RSA演算法來進行加密(RSA演算法是非對稱加密,參見《對稱加密與非對稱加密 》),公鑰存放在config文件當中,只有加密的計算機有密鑰。通常是默認的預設provider。
(二)加密文件的命令
加密web.config文件可以使用:
aspnet_regiis -pef section web-app-physical-dir
Encrypt the configuration section. Optional arguments:
[-prov provider] Use this provider to encrypt.

比如運行下面的命令就會分別對connectionStrings和appSettings中的信息進行加密:

aspnet_regiis.exe -pef "connectionStrings" "C:\myweb\HelloService"
aspnet_regiis.exe -pef "appSettings" "C:\myweb\HelloService"

加密後的web.config文件變成:

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation targetFramework="4.0" />
</system.web>
<connectionStrings configProtectionProvider="">
<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#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>E2fO9C0TJVxImLYQZza+fCQdDbTpNh/kOKLRsK6zcFjkgtUCl6SnMViuu/2G1NVTxqXyEWYwyK6AiCZA+feeG/+f2EIimP7LJI+JRZVerI4MU6Ke3wxm2S/ATc73/W6eg9808f4//JB0kso0kGJ9i+==</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>I1DWG11Iz/rq+NC9C/21B3Q22J9+//JW1oCvAGs5tHrZU5+vgvm0yCmSuCWZbXva+iv9J35EQqs58pq+hwVo1hg1dffpGCBykaXGl5VX3TIGc=</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
<appSettings configProtectionProvider="">
<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#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>//SuBvV3D2kxhHaYGFaPuvYgsyOLf3+aYR3O/uh/+/iSANzAWoC+==</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>5W2KhG/oETLUDptobcOM52x1qD/g9A0By/wcGXI+///w=</CipherValue>
</CipherData>
</EncryptedData>
</appSettings>
</configuration>

是默認的預設provider,如果想使用,可以用-prov參數指明:

aspnet_regiis.exe -pef "connectionStrings" "C:\myweb\HelloService" -prov ""
aspnet_regiis.exe -pef "appSettings" "C:\myweb\HelloService" -prov ""

加密配置文件後,源程序不需要做任何改動。如果要修改或添加新的配置信息,需要先解密配置文件。不論使用哪種Provider,都只能在進行加密的計算機上對配置文件進行解密。

閱讀全文

與gs5加密封條相關的資料

熱點內容
linux時間調度演算法 瀏覽:767
單片機最小電路詳解 瀏覽:181
請求要求命令 瀏覽:802
電腦文件夾發微信顯示被佔用 瀏覽:289
手機怎麼看加密視頻 瀏覽:202
怎樣解壓手機es文件包 瀏覽:659
2017年學什麼編程 瀏覽:930
金融期貨pdf 瀏覽:688
程序員客棧的信息保密嗎 瀏覽:505
編程顯示器什麼意思 瀏覽:144
網路編程的就業 瀏覽:258
s7200編程入門 瀏覽:747
華潤萬家app為什麼進不去 瀏覽:250
後台運行app命令 瀏覽:873
通達信雲加密能破解 瀏覽:141
郵件保存成pdf 瀏覽:867
bbs網站java源碼下載百度雲 瀏覽:460
php無限極分類樹 瀏覽:275
什麼叫高分伺服器 瀏覽:814
通達信最佳買點副圖指標源碼公式 瀏覽:182