0
私はwinformアプリケーションがあり、設定ファイルにいくつかの値を保存したいと思います。以下はその内容です。
.net 4.5では設定ファイルを暗号化できませんが、.net 3.5でも同じことができます
<configProtectedData>
<providers>
<add name="DataProtectionConfigurationProvider" type="System.Configuration.DpapiProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" description="Uses CryptProtectData and CryptUnProtectData Windows APIs to encrypt and decrypt" useMachineProtection="true" keyEntropy="" />
</providers>
</configProtectedData>
<appSettings>
</appSettings>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
私はまたそれゆえ、私はそれをenryptするには、次のコードを使用して、データを暗号化することにしたい。
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection(sectionName);
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
}
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Modified);
これは罰金WHの作品私はコンパイルし、VS 2008で.net 3.5を使用してコードを実行します。しかし、VS 2012を使用して.net 4.5を使用してコードをコンパイルすると、section.SectionInformation.ProtectSection( "DataProtectionConfigurationProvider")行で次のエラーが表示されます。設定ファイルに値を追加した後、ファイルを保存しようとすると、同じエラーが表示されます。
The entry 'DataProtectionConfigurationProvider' has already been added.
この理由は何ですか?
ありがとうございました。 –
DataProtectionConfigurationProviderバージョン2.0を.net 4.5でどのように使用できますか –