在WEB網站開發過程中,如果我們將資料庫連線字串封裝到.DLL檔案中,將會給資料庫和程式的遷移帶來麻煩,因為萬一伺服器地址或
者資料庫發生變更,那麼我們就不得不修改源程式並重新將其編譯。更好的解決方法是將資料庫連線字串寫入到web.config配置檔案中,可問題是將連
接字串寫入到web.config檔案中之後,任何人都能開啟看到所連線的資料庫名和密碼,又會帶來安全隱患,因此為了保證資料庫的安全性,我們可以通
過使用微軟IDE自帶的命令aspnet_regiis.exe將配置檔案web.config中指定的標籤進行加密,如果以後想檢視加密後的連線字元
串,我們還可以使用aspnet_regiis.exe將加密後的字串進行解密。
1. 加密通用語法
加密一個特定網站的web.config檔案的通用形式
aspnet_regiis.exe -pef secion physical_directory -prov provider
或
aspnet_regiis.exe -pe secion -app virtual_directory -prov provider
其中,各個引數的含義如下:
section表示要加密的配置節
physical_directory用於指定站點的物理路徑。
virtual_directory使用者指定虛擬路徑。
provider指定加密提供程式。
加密一個特定站點的連線字串就是:
aspnet_regiis.exe -pef "connectionStrings" "你的web專案路徑" -prov "DataProtectionConfigurationProvider"
其中DataProctionConfiguartionProvider是Windows資料保護API(DPAPI)提供程式,它使用Windows內建的密碼學技術來加解密配置節。預設情況下,這個提供程式使用本機的金鑰。
2. 加密方法
執行Visual Studio 2008命令提示
加密後的結果
<connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
<EncryptedData>
<CipherData> <CipherValue>
在WEB網站開發過程中,如果我們將資料庫連線字串封裝到.DLL檔案中,將會給資料庫和程式的遷移帶來麻煩,因為萬一伺服器地址或
者資料庫發生變更,那麼我們就不得不修改源程式並重新將其編譯。更好的解決方法是將資料庫連線字串寫入到web.config配置檔案中,可問題是將連
接字串寫入到web.config檔案中之後,任何人都能開啟看到所連線的資料庫名和密碼,又會帶來安全隱患,因此為了保證資料庫的安全性,我們可以通
過使用微軟IDE自帶的命令aspnet_regiis.exe將配置檔案web.config中指定的標籤進行加密,如果以後想檢視加密後的連線字元
串,我們還可以使用aspnet_regiis.exe將加密後的字串進行解密。
1. 加密通用語法
加密一個特定網站的web.config檔案的通用形式
aspnet_regiis.exe -pef secion physical_directory -prov provider
或
aspnet_regiis.exe -pe secion -app virtual_directory -prov provider
其中,各個引數的含義如下:
section表示要加密的配置節
physical_directory用於指定站點的物理路徑。
virtual_directory使用者指定虛擬路徑。
provider指定加密提供程式。
加密一個特定站點的連線字串就是:
aspnet_regiis.exe -pef "connectionStrings" "你的web專案路徑" -prov "DataProtectionConfigurationProvider"
其中DataProctionConfiguartionProvider是Windows資料保護API(DPAPI)提供程式,它使用Windows內建的密碼學技術來加解密配置節。預設情況下,這個提供程式使用本機的金鑰。
2. 加密方法
執行Visual Studio 2008命令提示
加密後的結果
<connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
<EncryptedData>
<CipherData> <CipherValue>