X509Certificate.Equals Метод

Определение

Сравнивает два объекта X509Certificate на равенство.Compares two X509Certificate objects for equality.

Перегрузки

Equals(Object)

Определяет равенство двух объектов X509Certificate.Compares two X509Certificate objects for equality.

Equals(X509Certificate)

Определяет равенство двух объектов X509Certificate.Compares two X509Certificate objects for equality.

Equals(Object)

Определяет равенство двух объектов X509Certificate.Compares two X509Certificate objects for equality.

public:
 override bool Equals(System::Object ^ obj);
[System.Runtime.InteropServices.ComVisible(false)]
public override bool Equals (object obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

Параметры

obj
Object

Объект X509Certificate, который требуется сравнить с текущим объектом.An X509Certificate object to compare to the current object.

Возвращаемое значение

Значение true, если текущий объект X509Certificate равен объекту, заданному параметром other; в противном случае — false.true if the current X509Certificate object is equal to the object specified by the other parameter; otherwise, false.

Атрибуты

Примеры

В следующем примере сравниваются два сертификата на равенство.The following example compares two certificates for equality.

using namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
   
   // The path to the certificate.
   String^ Certificate = "Certificate.cer";
   String^ OtherCertificate = "OtherCertificate.cer";
   
   // Load the certificate into an X509Certificate object.
   X509Certificate^ cert = X509Certificate::CreateFromCertFile( Certificate );
   
   // Load the certificate into an X509Certificate object.
   X509Certificate^ certTwo = X509Certificate::CreateFromCertFile( OtherCertificate );
   
   // Get the value.
   bool result = cert->Equals( certTwo );
   
   // Display the value to the console.
   Console::WriteLine( result );
}


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

public class X509
{

    public static void Main()
    {

        // The path to the certificate.
        string Certificate =  "Certificate.cer";
        string OtherCertificate =  "OtherCertificate.cer";

        // Load the certificate into an X509Certificate object.
        X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);

        // Load the certificate into an X509Certificate object.
        X509Certificate certTwo = X509Certificate.CreateFromCertFile(OtherCertificate);

        // Get the value.
        bool result = cert.Equals(certTwo);
       
        // Display the value to the console.
        Console.WriteLine(result);
    }
}
Imports System.Security.Cryptography.X509Certificates




Public Class X509
   
   
   Public Shared Sub Main()
      
      ' The path to the certificate.
      Dim Certificate As String = "Certificate.cer"
      Dim OtherCertificate As String = "OtherCertificate.cer"
      
      ' Load the certificate into an X509Certificate object.
      Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(Certificate)
      
      ' Load the certificate into an X509Certificate object.
      Dim certTwo As X509Certificate = X509Certificate.CreateFromCertFile(OtherCertificate)
      
      ' Get the value.
      Dim result As Boolean = cert.Equals(certTwo)
      
      ' Display the value to the console.
      Console.WriteLine(result)
   End Sub  
End Class 

Комментарии

Два объекта считаются равными, если они являются X509Certificate объектами и имеют один и тот же поставщик и серийный номер.Two objects are considered equal if they are X509Certificate objects and they have the same issuer and serial number.

Важно!

Метод Equals не следует использовать при сравнении сертификатов в целях безопасности.The Equals method should not be used when comparing certificates for security purposes. Вместо этого используйте хэш свойства RawData или свойства Thumbprint.Instead, use a hash of the RawData property, or the Thumbprint property.

Equals(X509Certificate)

Определяет равенство двух объектов X509Certificate.Compares two X509Certificate objects for equality.

public:
 virtual bool Equals(System::Security::Cryptography::X509Certificates::X509Certificate ^ other);
public virtual bool Equals (System.Security.Cryptography.X509Certificates.X509Certificate other);
override this.Equals : System.Security.Cryptography.X509Certificates.X509Certificate -> bool
Public Overridable Function Equals (other As X509Certificate) As Boolean

Параметры

other
X509Certificate

Объект X509Certificate, который требуется сравнить с текущим объектом.An X509Certificate object to compare to the current object.

Возвращаемое значение

Значение true, если текущий объект X509Certificate равен объекту, заданному параметром other; в противном случае — false.true if the current X509Certificate object is equal to the object specified by the other parameter; otherwise, false.

Примеры

В следующем примере сравниваются два сертификата на равенство.The following example compares two certificates for equality.

using namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
   
   // The path to the certificate.
   String^ Certificate = "Certificate.cer";
   String^ OtherCertificate = "OtherCertificate.cer";
   
   // Load the certificate into an X509Certificate object.
   X509Certificate^ cert = X509Certificate::CreateFromCertFile( Certificate );
   
   // Load the certificate into an X509Certificate object.
   X509Certificate^ certTwo = X509Certificate::CreateFromCertFile( OtherCertificate );
   
   // Get the value.
   bool result = cert->Equals( certTwo );
   
   // Display the value to the console.
   Console::WriteLine( result );
}


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

public class X509
{

    public static void Main()
    {

        // The path to the certificate.
        string Certificate =  "Certificate.cer";
        string OtherCertificate =  "OtherCertificate.cer";

        // Load the certificate into an X509Certificate object.
        X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);

        // Load the certificate into an X509Certificate object.
        X509Certificate certTwo = X509Certificate.CreateFromCertFile(OtherCertificate);

        // Get the value.
        bool result = cert.Equals(certTwo);
       
        // Display the value to the console.
        Console.WriteLine(result);
    }
}
Imports System.Security.Cryptography.X509Certificates




Public Class X509
   
   
   Public Shared Sub Main()
      
      ' The path to the certificate.
      Dim Certificate As String = "Certificate.cer"
      Dim OtherCertificate As String = "OtherCertificate.cer"
      
      ' Load the certificate into an X509Certificate object.
      Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(Certificate)
      
      ' Load the certificate into an X509Certificate object.
      Dim certTwo As X509Certificate = X509Certificate.CreateFromCertFile(OtherCertificate)
      
      ' Get the value.
      Dim result As Boolean = cert.Equals(certTwo)
      
      ' Display the value to the console.
      Console.WriteLine(result)
   End Sub  
End Class 

Комментарии

Два X509Certificate объектов считаются равными, если они имеют одинаковый поставщик и серийный номер.Two X509Certificate objects are considered equal if they have the same issuer and serial number.

Важно!

Метод Equals не следует использовать при сравнении сертификатов в целях безопасности.The Equals method should not be used when comparing certificates for security purposes. Вместо этого используйте хэш свойства RawData или свойства Thumbprint.Instead, use a hash of the RawData property, or the Thumbprint property.

Применяется к