Visual C# Developer Center > Visual C# Forums > Visual C# General > RSA.ImportCspBlob: Bad Provider
Ask a questionAsk a question
 

QuestionRSA.ImportCspBlob: Bad Provider

  • Saturday, November 07, 2009 4:12 PMCaian Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi all, i am porting a code from C++ to C# that uses OpenSSL and RSA. Basically i have the private key (1024 bits) and i want to decrypt a chunk of data. The key and the chunk are the same i use in rsa_decrypt(), but i'm gettig Bad Provider from ImportCspBlob(); Here is the code:


    public static byte[] DecryptRSA(byte[] data, byte[] key)
            {
                byte[] decrypted = null;

                try
                {
                    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
                    rsa.ImportCspBlob(key);
                    decrypted = rsa.Decrypt(data, false);
                }
                catch
                {
                }

                return decrypted;
            }

    Am i doing something wrong?

All Replies

  • Thursday, November 12, 2009 1:30 PMChao KuoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello, Caian
    You are doing nothing wrong in your current code, if there is nothing wrong with your key. I doubt there is something wrong with your key, Is your key is exported through the ExportCspBlob(bool) method?
    Could you post your Encrypt Code here? I am not able to find any clue according such a little code.
    Thanks
    Chao

  • Thursday, November 12, 2009 11:16 PMCaian Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The key and the data chunk were provided for testing the final application and i don't have access to source for the encoder, but since the work involves porting the decoder from native C++ code i guess that the key was created using OpenSSL because the decorder uses OSSL libs and the key (and data) works like a charm with rsa_decrypt().

    I am trying to use RSA.ImportCspBlob because it was the only method i found in C# that actually accepts a already-buit key without all that "register stuff". I assumed that a RAW key was compatible with this function.
  • Friday, November 13, 2009 7:42 AMChao KuoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello, Caian
    If there is something wrong with your key, your provider would be wrong. So make your key right, does your converting from string to byte[] using System.Text.Encoding.ASCII.GetString method? If not please try to use this method.
    Thanks
    Chao
  • Friday, November 13, 2009 3:34 PMCaian Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I tested in the C++ application myself and it works, the key is not a string, i received it as a byte array and considering the contents it's not a hex string nor a understandable string.

    Another possibility is the key is not in a Blob format, if so, is there any other way to set a custom key to the RSA Service?

    Thanks,
    Caian