aspnet_regiis web.config encryption [Error message from the provider: Bad Data.]

前提是你 提交于 2021-01-29 01:57:57

问题


I'm trying to encrypt a web app's web.config, but this application exists on 2 different environments (stage, production), each of which should use a different key container.

So I'm using this encryption header on my stage config:

<configProtectedData defaultProvider="ApplicationProvider">
<providers>
  <add name="ApplicationProvider"
    type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
    keyContainerName="ApplicationStageKeys"
    useMachineContainer="true"
    useOAEP="true"/>
</providers>

And this header on my production config:

<configProtectedData defaultProvider="ApplicationProvider">
<providers>
  <add name="ApplicationProvider"
    type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
    keyContainerName="ApplicationProductionKeys"
    useMachineContainer="true"
    useOAEP="true"/>
</providers>

Encryption works fine but everytime I try to decrypt, I'm getting the following error which leaves far too much to the imagination....

C:\Windows\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis -pdf connectionStrings C:\Temp

Decrypting configuration section...
Failed to decrypt using provider 'ApplicationProvider'. Error message from the provider: Bad Data.
(C:\Temp\web.config line 75)

Bad Data.

Failed!

I've imported the keys on each server and set up ACLs for both but still no joy, any else ever have this problem?


回答1:


After looking through it I found a fix, our security guy asked us to turn the 'useOAEP' flag to 'true', I removed this and the encryption and decryption works perfectly!

I wish I could explain why this fixed it but when all your provided is a dumb error message (Bad Data!) you can't exactly expect a smart explanation.

Here's what our encryption headers looks like now:

<configProtectedData defaultProvider="ApplicationProvider">
<providers>
<add name="ApplicationProvider"
     type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
     keyContainerName="ApplicationProductionKeys"
     useMachineContainer="true"/>
</providers>

Hopefully this will save others a few inches on their hairline when they attempt encryption



来源:https://stackoverflow.com/questions/22533198/aspnet-regiis-web-config-encryption-error-message-from-the-provider-bad-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!