Activation error occured while trying to get instance of type ISymmetricCryptoProvider, key \"SymetricMethod\

Aug 15, 2012 at 5:20 PM

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="securityCryptographyConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Configuration.CryptographySettings, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>

  <startup>
   
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
 

  <securityCryptographyConfiguration>
    <hashProviders>
      <add name="HashingMethod" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.HashAlgorithmProvider, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        algorithmType="System.Security.Cryptography.SHA1Managed, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        saltEnabled="true" />
    </hashProviders>
    <symmetricCryptoProviders>
      <add name="RijndaelManaged" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.SymmetricAlgorithmProvider, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          algorithmType="System.Security.Cryptography.RijndaelManaged, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          protectedKeyFilename="C:\key\aes.key" protectedKeyProtectionScope="LocalMachine" />
    </symmetricCryptoProviders>
  </securityCryptographyConfiguration>
  <appSettings>
    <!--Espacio donde Se calcula el periodo que debe transcurrir para ejecutar la busqueda de alertas, Unidad en segundos -->
    <add key="TiempoNotificacionAlerta" value="120" />
    <add key="IdAplicacion" value="1" />
    <add key="UrlGestion" value="www.google.com" />
  </appSettings>
  <connectionStrings>
    <!--<add name="ConnectionString - DDVI" connectionString="Data Source=PRODUCCION\PRODUCCION;Initial Catalog=HabitatMetamodelo;Persist Security Info=True;User ID=sqlpn;Password=sqlpn;User Instance=False"
      providerName="System.Data.SqlClient" />-->
    <!--<add name="ConnectionString - DDVIH" connectionString="Data Source=172.16.2.99;Initial Catalog=HabitatDDVI_Historic;Persist Security Info=True;User ID=userGs1;Password=ViewSonic2.;User Instance=False"
      providerName="System.Data.SqlClient" />-->
    <add name="ConnectionString - MTM" connectionString="Data Source=PRODUCCION\PRODUCCION;Initial Catalog=HabitatMetamodelo;Persist Security Info=True;User ID=sqlpn;Password=sqlpn;User Instance=False"
      providerName="System.Data.SqlClient" />
    <!--<add name="ConnectionString - CRM" connectionString="Data Source=172.16.0.10;Initial Catalog=GS1LOGCRM;Persist Security Info=True;User ID=CASADMIN;Password=GS12010*;User Instance=False"
          providerName="System.Data.SqlClient" />-->
  </connectionStrings>
 
 
</configuration>

Please, if someone can help me, I would appreciate so much!!

 

Thanks,

 

 

Aug 16, 2012 at 3:30 AM

The configuration is good.  The message indicates that the container is looking for a key called "SymetricMethod" which doesn't appear in the configuration.

This code should work with the posted configuration:

    var provider = EnterpriseLibraryContainer.Current.GetInstance<ISymmetricCryptoProvider>("RijndaelManaged");

That assumes that the key provided in the configuration ("C:\key\aes.key") exists.  If it doesn't exist then you will also get an ActivationException.  You should check in the InnerException property to see the details.  For example if the key file was wrong (did not exist or some permission issue, etc.) the InnerException.Message would be something like:

Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.ISymmetricCryptoProvider", name = "RijndaelManaged".
Exception occurred while: Calling constructor Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.SymmetricAlgorithmProvider(System.Type algorithmType, System.String protectedKeyFileName, System.Security.Cryptography.DataProtectionScope protectedKeyProtectionScope, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Instrumentation.ISymmetricAlgorithmInstrumentationProvider instrumentationProvider).
Exception is: FileNotFoundException - Could not find file 'C:\key\aes.key'.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com