Secure Connection String when using data source control i.e Encrypt/ Decrypt the connection string in Web.config file.

In this blog, i am going to explain how to encrypt/ decrypt the Connection Strings in web.config file in Asp.Net

Encrypt connectionString


Step 1:: Goto Visual Studio Developer Command Prompt
 Goto --> C:\Windows\System32\cmd.exe
 Then type--> cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
Step 2:: Now type following command ::
             
       aspnet_regiis -pef connectionStrings "e:\aayush singh\CRM2013reportsext\CRMwebPortal" -prov DataProtectionConfigurationProvider

Here –pef indicates that the application is built as File System website. Second argument connectionStrings indicates that name of the configuration section needs to be encrypted. The Third argument is the physical path of the folder where the web.config file is located.

Step 3:: After enter the command click enter if everything goes well you get a success message like “Encrypting configuration section… Succeeded!” [See below the screenshot]




Step 4:: Now, goto your solution check your connectionString in web.config file. you will notice that the connectionString has been encrypted like below ::

<connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
    <EncryptedData>
      <CipherData>
        <CipherValue>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAQ2oQjb0zBkS0fUV0GAFv7QQAAAACAAAAAAAQZgAAAAEAACAAAAAmqtERQRQeaPZiu5YOuEK73pvBHMD4gBg9X8jwB+lvXgAAAAAOgAAAAAIAACAAAACDy9ExDd+6eJos6q5iRkKsmOSwnvdEWlAWILOpINFMIqABAADEuB/o0tUA61OY37n9W+hvREAFL08K8hve1MKRinMOINGte2fEC9Xq2yRz3om2Xiw057jwYGJk/MlxZ7i+CWhwmBYw4mD8S+3cRotDSsvhYMhT/YKVqQZ1+Nh7RZ77ogKTq3efGEIjITHfpi7TzDB8n7oktEDR5f1//pvQdpCh+4ky+wHlBfGXZr8yHyquhmNuKcp31SzKnl0jOn/wVPZnJqr4aqMgNCV+z/VBlW6g/iUo4y1yurAt7cKjw7WnrYvTA3LG/Ss1bXYVLyHHxVzdgIrV9IHU277XfrDCqQ6ZT0nDR2SvumJrAwzE9GCDiDZMUQuoCH2cD6Rm/9topZkTpV6DKwYitpJQjW7jhgIFB2F9URIH2UTFyP9YmCLFXsGCde+QVX4J8YZPWvPlKmSIQ2C685W+E1/4SgVlBn067SBYygOsSsLzJiidXlv5TM1DbSZ2/rP48emCxd1DrsTMpovW8TFKQF1Hl/vlYCfdk4ijFgp/ABUOHL/Hv86N+ryhhNQlGhqhvoZg87VTrYIEXoUakhNroynQAkP8tyNUPEAAAAB0eoI41iVKFkl0Ktw7ble34lljpXrq1cYtjZRNgblEalvbDn0Q2tnop7c3TglAyul6O8EoaAHHByJHkukIpWli</CipherValue>
      </CipherData>
    </EncryptedData>
</connectionStrings>


Decrypt connectionString


1. Now, For Decrypting connectionString just go from Step 1 and step2 and type below command in command prompt ::


       aspnet_regiis -pdf connectionStrings "e:\aayush singh\CRM2013reportsext\CRMwebPortal"

2. After enter the command click enter if everything goes well you get a success message like “Decrypting configuration section… Succeeded!” [See below the screenshot]




3. Now, goto your solution check your connectionString in web.config file. you will notice that the connectionString has been decrypted like below ::



<connectionStrings>
    <add name="CRM" connectionString="Url=https://xyzSolution.crm5.dynamics.com; Username=aayush.singhl@xyzSolution.onmicrosoft.com; Password=Pass@1234" />
  </connectionStrings>
</configuration>

Comments

Popular posts from this blog

StateCode and StatusCode Values for mostly used entities in Microsoft Dynamics CRM 2013

How to import CSV files into DataTable in C#

Search data in Gridview on Textbox Key press event using JQuery in Asp.Net- C#

go to top image