Thursday, December 9, 2010

Encrypted Connection Strings using aspnet_regiis.exe

I had a task to encrypt connectionstrings of a project, i decided to use aspnet_regiis.exe file which i studied for my MCTS certification paper

Using Visual Studio Command Prompt,

Encrypt ConnectionString
[Generic form for encrypting the Web.config file for a particular website]
Inorder to encrypt specifying a path to physical directory
aspnet_regiis.exe -pef section physical_directory –prov provider
-- OR --
In order to encrypt with the name of virtual directory
aspnet_regiis.exe -pe section -app virtual_directory –prov provider

Example:
aspnet_regiis.exe -pef "connectionStrings" "D:\Publish\MyProject\1" –prov "DataProtectionConfigurationProvider"
-- OR --
aspnet_regiis.exe -pe "connectionStrings" -app "/MySite" –prov "DataProtectionConfigurationProvider"
*Note: This will add encrypteddata, cipherdata, ciphervalue tags in connectionstrings tag
----------------------------------
Decrypt ConnectionString
[Generic form for decrypting the Web.config file for a particular website]
Inorder to decrypt specifying a path to physical directory
aspnet_regiis.exe -pdf section physical_directory
-- OR --
Inorder to decrypt with the name of virtual directory
aspnet_regiis.exe -pd section -app virtual_directory

Example:
aspnet_regiis.exe -pdf "connectionStrings" "D:\Publish\MyProject\1"
-- OR --
aspnet_regiis.exe -pd "connectionStrings" -app "/MySite"
*Note: No provider is required for decryption as it will pick from webconfig file itself

Happy Dotnetting!~