简体   繁体   English

NET Framework 4.5中如何使用System.Configuration.DpapiProtectedConfigurationProvider版本2?

[英]How to use System.Configuration.DpapiProtectedConfigurationProvider version 2 in .net framework 4.5?

I recently upgraded my application from .net 3.5 to .net 4.5 .I maintain a config file in which I store user data.And that data is encrypted using System.Configuration.DpapiProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 我最近将应用程序从.net 3.5升级到.net 4.5。我维护了一个配置文件,用于存储用户数据。并且使用System.Configuration.DpapiProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

After, upgrading when I tried to access data from the config file, it gave following error: 之后,升级后,当我尝试从配置文件访问数据时,出现以下错误:

The entry 'DataProtectionConfigurationProvider' has already been added.

So, I removed the entry from the DataProtectionConfigurationProvider entry from the file.After that when I tried to access the file, I got following exception: 因此,我从文件的DataProtectionConfigurationProvider条目中删除了该条目。之后,当我尝试访问文件时,出现以下异常:

Failed to decrypt using provider 'DataProtectionConfigurationProvider'. Error message from the provider: Key not valid for use in specified state. (Exception from HRESULT: 0x8009000B)

Here is my config file: 这是我的配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration> 
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="CustomPane_outlookAddIn.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.serviceModel>
    <bindings />
    <client />
  </system.serviceModel>

  <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 configProtectionProvider="DataProtectionConfigurationProvider">
    <EncryptedData>
      <CipherData>
        <CipherValue>Encrypted user data</CipherValue>
      </CipherData>
    </EncryptedData>
  </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>

从配置文件中删除“ DataProtectionConfigurationProvider”条目后,它可以工作。问题是我正在使用另一台计算机上的配置文件,并且密钥存储在从中获取配置文件的计算机中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在4.5 .NET Framework版本中构建Web API? - How to build web api in 4.5 .net framework version? 如何在 Unity 5 中使用 .NET 框架 4.5 - How can I use .NET framework 4.5 in Unity 5 此设置需要 .NET Framework 4.5 版 - This setup requires .NET Framework version 4.5 System.CommandLine 与 .NET Framework 4.5 - System.CommandLine with .NET Framework 4.5 如何使用.Net Framework 3.5或4.5取决于哪些可用 - How to use .Net Framework 3.5 or 4.5 depending on which ever is available 如何在只有.NET Framework 4.0和4.5的系统上支持.NET Framework 3.0 WPF应用程序? - How to support .NET Framework 3.0 wpf application on the system that has only .NET Framework 4.0 & 4.5? 在.Net Framework中使用最新版本的System.Net.Http - Use latest version of System.Net.Http in .Net Framework 用于connectType版本的log4net配置和用于.NET 4.5的公钥 - log4net configuration for connectionType version and public key for .NET 4.5 DpapiProtectedConfigurationProvider 中使用的加密方法是什么? - What is the Encryption method use in DpapiProtectedConfigurationProvider? 在PCL中使用System.Net.Sockets(.Net 4.5 + phone 8) - Use System.Net.Sockets in PCL (.Net 4.5 + phone 8)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM