CSP for this implementation could not be acquired

From: MikeWorkflow (MikeWorkflow_at_discussions.microsoft.com)
Date: 12/13/04

  • Next message: Eric: "Shared Drive and EXE"
    Date: Mon, 13 Dec 2004 07:35:06 -0800
    
    

    Greetings all,

    I'm having difficulty tracking down the cause of this
    CryptographicException. After looking through the web, I can find plenty of
    cases where people are having this problem using ASP.NET. However, this
    problem is happening in a desktop application, not in ASP.NET.

    Furthermore, the problem is only occurring in one client's workstation. This
    same application has been installed in on several test machines and client
    machines and none have had this problem.

    I'm using RSACryptoServiceProvider.EncryptBytes to take a string, convert it
    to bytes, and encrypt the string in a CSP specified by name.

    Here's the code:
    public static byte[] RSAEncryptBytes(byte[] unencryptedData, string
    containerName, bool OAEPPadding)
    {
            CspParameters csp = new CspParameters();
            csp.KeyContainerName = containerName;

            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csp);
                    return rsa.Encrypt(unencryptedData,OAEPPadding);
    }

    public static string RSAEncryptString(string unencryptedString, string
    containerName)
    {
            System.Text.UnicodeEncoding encoding = new System.Text.UnicodeEncoding();
            byte[] unencryptedBytes, encryptedBytes;

            unencryptedBytes = encoding.GetBytes(unencryptedString);
                    encryptedBytes =
    RSAEncryptBytes(unencryptedBytes,containerName,false);

                     return Convert.ToBase64String(encryptedBytes);
    }

    public static void Main()
    {
           string sContainerName = "MyCSPContainer";
           string sUnencryptedVal = "Hello, I'm unencrypted";
           string sEncryptedVal;

          sEncryptedVal = RSAEncryptString(sUnencryptedVal,sContainerName);
    }

    The exception "CryptographicException: CryptoAPI cryptographic service
    provider (CSP) for this implementation could not be acquired" is thrown.

    The user is running Windows XP Professional, .NET Framework 1.1.

    Does anyone have any insight as to why this single client is having
    problems, when all others don't?


  • Next message: Eric: "Shared Drive and EXE"