How to compare two X509Certificate2 C #

How can I compare two X509Certificate2 objects?

I need to find out if the two certificates match. This is for user authentication, and I need to find out if both certificates are the same person.

Can I use its serial number or thumprint properties? or are there other ways?

I am also new to this and would like to know if it is safe to use X509Certificate for user authentication?

+6
source share
2 answers

A fingerprint is a unique value for a certificate; it is usually used to search for a specific certificate in a certificate store. More details

Serial number - , . ...

+10

( X509).

X509Certificate Equals() :

, X509Certificate .

using System;
using System.Security.Cryptography.X509Certificates;

public class X509
{

    public static void Main()
    {
        // The paths to the certificate signed files
        string Certificate =  @"Signed1.exe";
        string OtherCertificate = @"Signed2.exe";

        // Starting with .NET Framework 4.6, the X509Certificate type implements the IDisposable interface...
        using (X509Certificate certOne = X509Certificate.CreateFromCertFile(Certificate))
        using (X509Certificate certTwo = X509Certificate.CreateFromCertFile(OtherCertificate))
        {
            bool result = certOne.Equals(certTwo);

            Console.WriteLine(result);
        }
    }

}
+1

All Articles