none
Load PFX in Compact Framework 3.5 RRS feed

  • Question

  • Hi

    I need to create a X509Certificate2 with a byte array.

    The byte array is from a PFX certificate which is passwordless.

     

                FileStream fs = File.Open("mycert2.pfx", FileMode.Open, FileAccess.Read);

                byte[] buffer = new byte[fs.Length];

                int count = fs.Read(buffer, 0, buffer.Length);

                fs.Close();

                X509Certificate2 cert = new X509Certificate2(buffer);

     

    but when i try to create the object a receive the message:

    Creating certificate object failed. The data passed in is either incorrect or is not supported by .NET Compact Framework. .NET Compact Framework does not support reading from pfx files.
    StackTrace
       at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData)
       at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] data)
       at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)

     

    is it possible to do this in Compact Framework 3.5?

    • Moved by Rudedog2 Friday, July 16, 2010 6:22 PM : Issue is Off-Topic (From:Visual C# Language)
    Friday, July 16, 2010 5:16 PM

All replies

  • Hello,

    I have a same problem did you find any solution??????

    • Proposed as answer by vivekanand Friday, March 25, 2011 10:09 AM
    Wednesday, September 15, 2010 8:30 AM
  • Hi All,

    The .net compact framework does not support getting the private key from x509certificate2.

    I need to get the private key from x509certificate2 in .net compact framework.

    If i have TestCert.pfx file. How can I extract the private key by using this password.

    Regards, Vivek


    Vivek
    Friday, March 25, 2011 10:10 AM
  • I am facing the same issue
      I am trying to use SSL certificate in my code in Windows Mobile 6.0 and add it to   store via code.and I am getting this
    //Creating certificate object failed. The data passed in is either incorrect or is not supported //by .NET Compact Framework. .NET Compact Framework does not support reading from pfx files.


      //Below is the code :

    {

                    string certificatepath = "\Program Files\EmbedCertificatePOC\alerts.cer";


                    byte[] bcertificate = ReadAllBytes(certificatepath);


                    X509Store store = new X509Store("teststore", StoreLocation.CurrentUser);
                    store.Open(OpenFlags.ReadWrite);

                    X509Certificate2 certificate1 = new X509Certificate2(bcertificate);
                                   
      //In above line,Here I am Getting Error

    //Creating certificate object failed. The data passed in is either incorrect or is not supported //by .NET Compact Framework. .NET Compact Framework does not support reading from pfx files.

                    store.Certificates.Add(certificate1);
    }

            public byte[] ReadAllBytes(string fileName)
            {
                byte[] buffer = null;
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, (int)fs.Length);
                }
                return buffer;
            }

     

    Can anybody help and provide the solution ....is it that .NET 3.5 Compact framework doesnot support this or any have made any mistake in code....

    Wednesday, April 9, 2014 4:11 PM