網站here(如下所示)上的代碼加密app.config。我按下了一個按鈕來加密我的配置。加密配置
當我要運行代碼 - (例如在應用程序啓動時,如果它尚未加密)? 在我的bin文件夾中,我有2個xml配置文件(Applicationname.exe.config和Applicationname.vshost.exe - 此代碼僅對它們中的第一個進行加密 - 當我部署我的程序時,我如何確保我的客戶沒有意外獲得的解密文件還因爲這將是一個重大的問題?(或者根本保證這個Windows安裝程序照顧)?
C#代碼
Configuration config = ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
SectionInformation appSettingsSecInfo = config.GetSection(
"appSettings").SectionInformation;
if (!appSettingsSecInfo.IsProtected)
{
Console.WriteLine("The configuration file has NOT been protected!");
// Encrypt this section by using security provider
// (RsaProtectedConfigurationProvider or DpapiProtectedConfigurationProvider).
appSettingsSecInfo.ProtectSection("RsaProtectedConfigurationProvider");
appSettingsSecInfo.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
我相信我是正確的,你說你需要在安裝應用程序時運行它,因爲所使用的加密是特定於計算機的。在PC上加密會導致一個配置文件無法在另一臺PC上讀取。 –
聽起來像它可能會打破等方法 - 我會回去看看是否有一個更簡單的方法。我無法冒密碼開放的風險。謝謝您的幫助。 – user1438082