none
How to export Certificate to PKCS# 7 format (.p7b file) RRS feed

  • Question

  • I am trying below code to export a certificate from machine store to PKCS# 7 format, but it fails with exception

     

    System.Security.Cryptography.CryptographicException was unhandled

      Message=Invalid content type.

      Source=mscorlib

      StackTrace:

           at System.Security.Cryptography.X509Certificates.X509Certificate.ExportHelper(X509ContentType contentType, Object password)

           at System.Security.Cryptography.X509Certificates.X509Certificate.Export(X509ContentType contentType)

     

     

     

    var chSignatureCert = machineStore.Certificates.Find(X509FindType.FindByThumbprint, "30 a7 1b 77 d7 71 a6 36 e7 c3 a3 e3 b7 80 a9 81 50 84 34 b0"false)[0];

    chSignatureCert.Export(X509ContentType.Pkcs7);

     

     

    Can anyone provide any inputs on how to export cert in PKCS# 7 format?


    singhhome
    Monday, June 27, 2011 6:57 PM

All replies

  •  

    Hi,

     

    Welcome to the MSDN forum.

     

    Have you debug the code to see whether the chSigntureCert object in your code has got the Certificate? Does it contain a password in it?

     

    More information, please refer to:

    X509Certificate.Export Method


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 28, 2011 7:58 AM
  • sorry for late reply. I still don't have a solution for this.

    I can read other properties of certificate and it does not have any password.

     

    Regards


    singhhome
    Saturday, August 6, 2011 10:58 AM
  • You can only export in pkcs7 format from the X5092Certificate Collection.

    var collection = new X509Certificate2Collection(chSignatureCert );

    var data = collection.Export(X509ContentType.Pkcs7);


    Tuesday, April 4, 2017 1:23 PM