0

I have to encrypt my web.config with section.sectioninformation.protectsection() and same web.config will run over 3 servers.

Is There any Possible way to accomplish this task.

  • As Per the following link : https://www.codeproject.com/Tips/877258/How-to-Encrypt-Web-config-Using-aspnet-regiis-exe you will have to use **aspnet_regiis.exe** . for example `aspnet_regiis.exe -pef` command (Encryption) This command encrypt a specific section in a specific hard drive location, so for example to encrypt “appSettings” section in site located at “C:\inetpub\wwwroot\app\WebConfigEncryption” run: `aspnet_regiis.exe -pef appSettings C:\inetpub\wwwroot\app\WebConfigEncryption` – Nirzar Sep 15 '17 at 13:11

2 Answers2

0

I've never done this programmatically but using aspnet_regiis.exe, add the following section to the web.config file. N.B. Make sure the type information is correct - look at machine.config.

<configProtectedData defaultProvider="myRsaProvider">
   <providers>
      <add name="myRsaProvider"
           type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
           keyContainerName="myRsaKeys"
           useMachineContainer="true" />
   </providers>
</configProtectedData>

Create an exportable machine-level RSA key container

aspnet_regiis -pc "myRsaKeys"–exp 

Grant permissions to the key container

aspnet_regiis -pa "myRsaKeys" "yourDomain\yourUsername"

Encrypt appSettings section of web.config in c:\temp\ using the custom RsaProtectedConfigurationProvider, myRsaProvider

aspnet_regiis -pef "appSettings" c:\temp\ -prov "myRsaProvider"

Export the RSA key container

aspnet_regiis -px "myRsaKeys" myRsaKeys.xml -pri

Import the RSA key container on any machine where you install the web.config.

aspnet_regiis -pi "myRsaKeys" myRsaKeys.xml
spodger
  • 1,668
  • 1
  • 12
  • 16
0

Check out this article: https://msdn.microsoft.com/en-us/library/ms998283.aspx

Command:

aspnet_regiis.exe -pef "connectionStrings" C:\Projects\MachineRSA

Sources:

https://stackoverflow.com/a/976117/3850405 https://stackoverflow.com/a/5717845/3850405 How to encrypt web.config section AND deploy to multiple servers with Amazon Elastic Beanstalk

Ogglas
  • 62,132
  • 37
  • 328
  • 418