Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Below web.config is used in MVC Web Application. I need to encrypt appSettings.config and connections.config which is external to web.config using configSource.

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings configSource="appSettings.config"/>
<connectionStrings configSource="connections.config"/>
<system.web>
<compilation debug="true" />
<authentication mode="Windows"/>
<identity impersonate="true"/>

What I have tried:

I tried to encrypt using RsaProtectedConfigurationProvider with aspnet_regiis. But it is not working as expected in simple Web.config where appSettings and connectionStrings present at the same file.


I am using below command to encrypt web.config 
C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -pef "connectionStrings" "D:\WebApplication" -prov "AppEncryptionProvider".                                         C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -pef "appSettings" "D:\WebApplication" -prov "AppEncryptionProvider

but while using this in a web application it gives me the error as below:         Failed to decrypt using provider 'AppEncryptionProvider'. Error message from the provider: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

XML
Line 1:  <appSettings configProtectionProvider="AppEncryptionProvider">
Line 2:    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
Line 3:      xmlns="http://www.w3.org/2001/04/xmlenc#">
Line 4:      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
Posted
Updated 21-Nov-17 18:21pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900