Hi all,
I'm using the RSACryptoServiceProvider and am getting the dreaded

"System.Security.Cryptography.CryptographicException: CryptoAPI
cryptographic
service provider (CSP) for this implementation could not be acquired."

It seems like this exception is common, but no real answer for it. I've
coded for 3 different scenarios, so *hopefully* I can add additional code
block for anymore
Here's my code. Any suggestions?

  private static RSACryptoServiceProvider AcquireRSA()
  {
       RSACryptoServiceProvider rsa = null;
   try
   {
    //first try with a container name, works in most ASP.NET situations
    CspParameters cspParams = new CspParameters();
    cspParams.KeyContainerName = BuildKeyContainerName();
    cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
    rsa = new RSACryptoServiceProvider( cspParams );
   }
   catch
   {
    try
    {
         //try without a container name (works on XP )
         CspParameters cspParams = new CspParameters();
         cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
         rsa = new RSACryptoServiceProvider( cspParams );
    }
    catch
    {
          //just try without any parameters: works for logged on user
          rsa = new RSACryptoServiceProvider( );
        }
   }

   return rsa;
  }

Thanks,
Dave

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

Essential .NET: building applications and components with C#
November 29 - December 3, in Los Angeles
http://www.develop.com/courses/edotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to