X509Certificate.Equals 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
比較兩個 X509Certificate 物件是否相等。
多載
Equals(Object) |
比較兩個 X509Certificate 物件是否相等。 |
Equals(X509Certificate) |
比較兩個 X509Certificate 物件是否相等。 |
Equals(Object)
比較兩個 X509Certificate 物件是否相等。
public:
override bool Equals(System::Object ^ obj);
public override bool Equals (object? obj);
public override bool Equals (object obj);
[System.Runtime.InteropServices.ComVisible(false)]
public override bool Equals (object obj);
override this.Equals : obj -> bool
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean
參數
- obj
- Object
要與目前物件比較的 X509Certificate 物件。
傳回
如果目前的 X509Certificate 物件等於 other
參數所指定的物件,則為 true
,否則為 false
。
- 屬性
範例
下列範例會比較兩個憑證是否相等。
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 物件,而且具有相同的簽發者和序號,則會將兩個對象視為相等。
重要
比較 Equals
安全性用途的憑證時,不應該使用 方法。 請改用 屬性的 RawData 哈希或 Thumbprint 屬性。
適用於
Equals(X509Certificate)
比較兩個 X509Certificate 物件是否相等。
public:
virtual bool Equals(System::Security::Cryptography::X509Certificates::X509Certificate ^ other);
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 物件。
傳回
如果目前的 X509Certificate 物件等於 other
參數所指定的物件,則為 true
,否則為 false
。
範例
下列範例會比較兩個憑證是否相等。
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如果兩個物件具有相同的簽發者和序號,則會視為相等。
重要
比較 Equals
安全性用途的憑證時,不應該使用 方法。 請改用 屬性的 RawData 哈希或 Thumbprint 屬性。