Home > C#

Cryptographer.DecryptSymmetric in App.config

24. February 2009

I just wanted to write this post for the first time users of the Microsoft.Practices.EnterpriseLibrary.Security.Cryptography library.  I was a bit confused on how to set this up in the config file and it just turned out that I needed to put my <connectionStrings> section below the Cryptography section. It was a little misleading because the exception I kept getting was "The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception."  I also kept getting an error saying that the "The symmetric crypto providersymprovider is not defined in the current configuration." Again, I just had everything ordered wrong in the App.Config.  So here is my app.config file with data taken out

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
  <section name="securityCryptographyConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Configuration.CryptographySettings, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography"/>
 </configSections>
 <securityCryptographyConfiguration>
  <symmetricCryptoProviders>
   <add name="symprovider" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.SymmetricAlgorithmProvider, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography"
     algorithmType="System.Security.Cryptography.RijndaelManaged, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
     protectedKeyFilename="C:\SymmProvider.key"
     protectedKeyProtectionScope="LocalMachine"/>
  </symmetricCryptoProviders>
 </securityCryptographyConfiguration>
 <connectionStrings>
      <add name="sqlConn" connectionString="yourEncryptedStringHere" />
 </connectionStrings> 
</configuration>

 The joys of using something for the first time..oh well nobody if perfect right. Hope this helps others out there as well.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

C# ,

blog comments powered by Disqus