Configuration File Decryption And Encryption Using Batch File

Introduction

 
In this blog, we are discussing web.configuration file encryption and decryption using a batch file.
 

What is the use of encrypting the web.configuration file?

 
We all know configuration files will have confidential data like a database connection string. Under the app settings section we used to have confidential data.  As per the security guidelines or applications, security says we need to encrypt the configuration file in the server. Let us see how we can encrypt and decrypt the configuration files using batch file instead of command prompt.
 
Step 1
 
Please create one text file and name it as encryption.bat. Please remember that file extension will be a .bat.
 
The below commands are useful for encrypting the app settings and connection strings in the configuration file.
  1. echo changing the directory    
  2. cd C:\Windows\Microsoft.NET\Framework\v4.0.30319    
  3. echo started  encrypting the connection strings     
  4. ASPNET_REGIIS -pef "connectionStrings" "file path"    
  5. echo success    
  6. echo started  encrypting the app settings      
  7. aspnet_regiis.exe -pef appSettings "file path"     
  8. echo success    
  9. Pause    
Note
File path should be pointing to your configuration file.
 
Step 2
 
The below commands are useful for decrypting the app settings and connection strings in the configuration file.
 
Please create one text file and name it as decrption.bat. Please remember that file extension will be a .bat. 
  1. echo changing the directory    
  2. cd C:\Windows\Microsoft.NET\Framework\v4.0.30319    
  3. echo started  decrypting  the  app settings     
  4. aspnet_regiis.exe -pdf appSettings "file path"     
  5. echo success    
  6. echo started decrypting connection strings     
  7. aspnet_regiis.exe -pdf "connectionStrings" "file path"    
  8. echo success    
  9. Pause    

Summary

 
In this blog, we discussed the configuration of file encryption and decryption using the batch file.