Search code examples
c#.netx509certificatex509x509certificate2

How can I get the signature of an X509Certificate2 object using C#?


I need to get the signature and the algorithm used to create that signature out of a certificate with C#.

Can I do that? If yes, how?


Solution

  • I am developing now application with similar functionality. And I'm really dissapointed why Microsoft didn't add property Signature to X509Certificate2 class

    I know how to do that via bouncycastle

    Take it from there http://www.bouncycastle.org/csharp/

    Then add code

    using System;
    using System.Security.Cryptography.X509Certificates;
    using bcrypto = Org.BouncyCastle.X509;
    

    .

    var cert = new X509Certificate2("c:\\temp\\0c50000343119659.cer");
    var certParser = new bcrypto.X509CertificateParser();
    var privateCertBouncy = certParser.ReadCertificate(cert.GetRawCertData());
    var xx = privateCertBouncy.GetSignature();
    Array.Reverse(xx);
    //Signature
    Console.WriteLine(BitConverter.ToString(xx));
    //algorithm
    Console.WriteLine(privateCertBouncy.SigAlgName);
    Console.ReadLine();