導航:首頁 > 文檔加密 > 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加密封條相關的資料

熱點內容
ug操作和產品命令 瀏覽:75
QQ在線表格怎麼加密 瀏覽:482
steam星際戰甲什麼伺服器 瀏覽:594
python重啟路由器腳本 瀏覽:819
java聊天窗口 瀏覽:976
單片機控制陣列led燈 瀏覽:577
白鹿用的什麼APP修圖 瀏覽:500
阿里雲輕量應用伺服器ssh無法連接 瀏覽:794
員工福利系統源碼 瀏覽:982
數據加密如何設置 瀏覽:570
php取余運算 瀏覽:153
php如何壓縮圖片大小 瀏覽:137
編程三階教程 瀏覽:983
pdf顏色查看 瀏覽:469
怎麼用指令停用命令方塊java 瀏覽:406
滑鼠命令行 瀏覽:567
如何朗讀pdf 瀏覽:746
壓縮機啟動後繼電器發燙 瀏覽:405
小學編程項目學習 瀏覽:558
net編譯運行原理 瀏覽:786