I know that ppl have already asked questions regarding encrypting web.config.
im also trying to encrypt my test config file, but im getting this error.
aspnet_re
I got an "illegal characters in path" error that went away when I removed the double quotes that surrounded my path name. Doesn't make any sense, but there you are.
I also wrote a PowerShell script to do the encrypt/decrypt without dealing with aspnet_regiis : https://github.com/mhenry1384/EncryptDecryptConfig
for the command "aspnet_regiis -pef" the path of configuration file is the physical path (Not virtual) and also it is the path of directory/folder where web.config resides. So one should not include the name of file in path e.g.
if your web.config path is at D:\MyConfiguration\web.config
then while encrypting/decrypting you will use it as follow:
encrypt:
aspnet_regiis -pef [sectionName] "D:\MyConfiguration"
decrypt:
aspnet_regiis -pdf [sectionName] "D:\MyConfiguration"
I was experiencing the same problem and here's what worked for me:
execute the command with the -pe argument and the -app argument like such:
aspnet_regiis -pe {section to encrypt} -app "{path from root folder to app, like: "/myappname", use quotes}
SecuredSettings
(any name is fine) either in you App.config or Web.config file. <configuration>
<configSections>
<section name="SecuredSettings" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<SecuredSettings>
<add key="pwrd" value="password" />
</SecuredSettings>
<configProtectedData>
<providers>
<add keyContainerName="MyCustomKeys"
useMachineContainer="true"
name="MyEncryptionProvider"
type="System.Configuration.RsaProtectedConfigurationProvider"/>
</providers>
</configProtectedData>
</configuration>
var attr = ConfigurationManager.GetSection("SecuredSettings") as NameValueCollection;
var value = attr["pwrd"];
C:\Windows\Microsoft.NET\Framework\v4.0.30319
aspnet_regiis.exe -pc MyCustomKeys -exp
aspnet_regiis.exe -pa MyCustomKeys "NT AUTHORITY\NETWORK SERVICE"
aspnet_regiis.exe -pef "SecuredSettings" "C:\DEV\ConsoleApp\DEX" -prov MyEncryptionProvider
aspnet_regiis.exe -px MyCustomKeys keys.xml -pri
it will generate keys.xml
file in C:\Windows\Microsoft.NET\Framework\v4.0.30319aspnet_regiis -pi MyCustomKeys keys.xml
aspnet_regiis.exe -pdf "SecuredSettings" "C:\DEV\ConsoleApp\DEX"
You could try and use this tool to encrypt you web config
The Sections are CASE SENSITIVE.
Do not Add \
at the end of the path (no web.config needed).
You don't need to do it straight on a site; instead, copy the file to any location.
Encrypting:
aspnet_regiis -pef "SECTIONTOENTRYPT" "d:\tempEnCrypt" -prov WhateverProviderYouAreUsing
Decrypting:
aspnet_regiis -pdf "SECTIONTOENTRYPT" "d:\tempEncrypt"
You can use this to encrypt an app.config as well, just rename the file for the encryption/decryption as web.config