X509Certificate.Equals Method (Object)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Compares two X509Certificate objects for equality.

Namespace:  System.Security.Cryptography.X509Certificates
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<ComVisibleAttribute(False)> _
Public Overrides Function Equals ( _
    obj As Object _
) As Boolean
[ComVisibleAttribute(false)]
public override bool Equals(
    Object obj
)

Parameters

  • obj
    Type: System.Object
    An object to compare to the current object.

Return Value

Type: System.Boolean
true if the current X509Certificate object is equal to the object specified by the other parameter; otherwise, false.

Examples

The following example compares two certificates for equality.

Imports System.Security.Cryptography.X509Certificates




Public Class Example


   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      ' 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.
      outputBlock.Text &= result & vbCrLf
   End Sub
End Class


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


public class Example
{

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {

      // 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.
      outputBlock.Text += result + "\n";

   }

}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.