The ASP.NET IIS Registration Tool (Aspnet_regiis.exe) can encrypt and decrypt sections of web.config. There is no special code required in an application, as ASP.NET 2.0 will magically decrypt sections at runtime.
The tool and runtime can also work together to encrypt and decrypt custom configuration sections. So if I have the following in web.config:
All I need to do from the command line, is:
It’s easier than a double pirouette…
Comments
If so, that's smart!
Glyn
Well, no, not that smart.
The example I have in the post will use a machine-specific key.
If you want to encrypt once and share amoung servers you'll need to use custom keys and the RSA provider, more details here: http://msdn2.microsoft.com/en-us/library/68ze1hb2(en-US,VS.80).aspx
For encrypt: aspnet_regiis.exe -pef "appSettings" "C:\temp"
For decrypt: aspnet_regiis.exe -pdf "appSettings" "C:\temp"
Here "C:\temp" is the physical location where the web.config file should exist
i am having issue while encryption in custom section.following is the configuration setting
<configSections>
<section
name="Pawan"
type="System.Configuration.SingleTagSectionHandler"
/>
</configSections>
<Pawan>
<Resources>
<Properties>
</Properties>
<Resources>
<add name="ConnectionString"
connectionString="Initial Catalog=DB;
data source=localhost;user id=sa;password=sa;"/>
</Resources>
</Resources>
<pawan/>
when i am trying to encrypt above connection string i am getting error section not found here you go for command
aspnet_regiis -pef "connectionStrings" "D:\TestProject\EncryptandDecrypt" prov "DataProtectionConfigurationProvider"
could you please help on the same
Thanks
Pawan Pawar
PAWAN... why do you have a Resources node in a Resources node? I don't think that is supported.
TIP: best to run this command from your root web folder (where your web.config resides)
C:\inetpub\wwwroot>C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pef "connectionStrings" .