Tuesday, 29 November 2011

Encrption And Decryption Of A Connection String

For Encryption Of A Coonection String  Run this command on command prompt of administrator
After open command prompt type the following command aspnet_regiis.exe -pef "connectionStrings" "E:\website1"

After open web.config file in application and add sample db connection in connectionStrings section like this 


<connectionStrings>
<add name="Constr" connectionString="Data Source= Yogi-pc /Family; Integrated Security=true;Initial Catalog= YourDatabaseName; uid=YourUserName; Password=yourpassword; " providerName="System.Data.SqlClient"/>
</connectionStrings >

Example of declaring connectionStrings in web.config file like this


<connectionStrings>
<add name="Constr" connectionString="Data Source=Yogi-pc /Family;Integrated Security=true;Initial Catalog=MySampleDB" providerName="System.Data.SqlClient"/>
</connectionStrings >


now open your connection string look like this



<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>ZNUbIEnOwlZzC8qbzHj5F2GS9gLYSkWCIgCJGkrgZAX8A+8oF</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>tODWlPD0Q/B/mP14GQ/5tUxcjmhHcy9a0oPunV5osNrMQRzt</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>

For Decryption Of Connection String Type this Command

 aspnet_regiis.exe -pdf "connectionStrings" "E:\website1"

No comments:

Post a Comment