Error after Encryptingweb.config

I encrypted the AppSettings part of my web.config, tested it on my machine, and it worked, but when I downloaded it to use it on the Internet, it gave me an error:

Configuration Error Description: An error occurred while processing the configuration file necessary to service this request. Please read the specific error details below and modify the configuration file accordingly.

Parser error message: could not be decrypted using the provider 'DataProtectionConfigurationProvider. Provider error message: The key is not valid for use in the specified state. (Exception from HRESULT: 0x8009000B)

Line 24: <appSettings configProtectionProvider="DataProtectionConfigurationProvider"> Line 25: <EncryptedData> 

I used the following sub for encryption:

 Private Sub ProtectSection(ByVal sectionName As String, ByVal provider As String) Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath) Dim section As ConfigurationSection = config.GetSection(sectionName) If section IsNot Nothing AndAlso Not section.SectionInformation.IsProtected Then section.SectionInformation.ProtectSection(provider) config.Save() End If End Sub 
+4
source share
2 answers

You need to publish the section with the section decryption. The key used for encryption / decryption depends on the specific computer.

To encrypt configuration sections online, call the ProtectSection () method in Application_Start () global.asax.

+3
source

You need to install MachineKey

.net encryption uses MachineKey as a seed for encryption / decryption

http://msdn.microsoft.com/en-us/library/w8h3skw9.aspx

You need to generate a key and use it on both machines. You also cannot use Autogenerate.

It’s easier to just download unencrypted and manually encrypt on the server, if possible, otherwise you need the same MachineKey

+1
source

All Articles