X509Certificate 類別

定義

提供協助您使用 X.509 v.3 憑證的方法。

public ref class X509Certificate : IDisposable, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public ref class X509Certificate : IDisposable
public ref class X509Certificate
public ref class X509Certificate : System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public class X509Certificate : IDisposable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class X509Certificate : IDisposable
[System.Serializable]
public class X509Certificate
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class X509Certificate : System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class X509Certificate : IDisposable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type X509Certificate = class
    interface IDisposable
    interface IDeserializationCallback
    interface ISerializable
type X509Certificate = class
    interface IDisposable
type X509Certificate = class
    interface IDisposable
    interface ISerializable
    interface IDeserializationCallback
[<System.Serializable>]
type X509Certificate = class
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type X509Certificate = class
    interface IDeserializationCallback
    interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type X509Certificate = class
    interface IDisposable
    interface IDeserializationCallback
    interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type X509Certificate = class
    interface IDeserializationCallback
    interface ISerializable
    interface IDisposable
Public Class X509Certificate
Implements IDeserializationCallback, IDisposable, ISerializable
Public Class X509Certificate
Implements IDisposable
Public Class X509Certificate
Public Class X509Certificate
Implements IDeserializationCallback, ISerializable
繼承
X509Certificate
衍生
屬性
實作

範例

下列範例會從檔案載入 X.509 憑證、呼叫 ToString 方法,並將結果顯示至主控台。

using namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
   
   // The path to the certificate.
   String^ Certificate = L"Certificate.cer";
   
   // Load the certificate into an X509Certificate object.
   X509Certificate^ cert = gcnew X509Certificate( Certificate );
   
   // Get the value.
   String^ resultsTrue = cert->ToString( true );
   
   // Display the value to the console.
   Console::WriteLine( resultsTrue );
   
   // Get the value.
   String^ resultsFalse = cert->ToString( false );
   
   // Display the value to the console.
   Console::WriteLine( resultsFalse );
}
using System;
using System.Security.Cryptography.X509Certificates;

public class X509
{

    public static void Main()
    {

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

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

        // Get the value.
        string resultsTrue = cert.ToString(true);

        // Display the value to the console.
        Console.WriteLine(resultsTrue);

        // Get the value.
        string resultsFalse = cert.ToString(false);

        // Display the value to the console.
        Console.WriteLine(resultsFalse);
    }
}
Imports System.Security.Cryptography.X509Certificates

Module X509

    Sub Main()

        ' The path to the certificate.
        Dim Certificate As String = "Certificate.cer"

        ' Load the certificate into an X509Certificate object.
        Dim cert As New X509Certificate(Certificate)

        ' Get the value.
        Dim resultsTrue As String = cert.ToString(True)

        ' Display the value to the console.
        Console.WriteLine(resultsTrue)

        ' Get the value.
        Dim resultsFalse As String = cert.ToString(False)

        ' Display the value to the console.
        Console.WriteLine(resultsFalse)

    End Sub
End Module

備註

ASN.1 DER 是唯一此類別支援的憑證格式。

在大部分情況下,您應該改用 X509Certificate2 類別。

重要

從 .NET Framework 4.6 開始,此類型會實作 IDisposable 介面。 當您完成使用型別時,您應該直接或間接處置它。 若要直接處置型別,請呼叫其 try/catch 區塊中的 Dispose 方法。 若要間接處置它,請使用語言建構函式,例如 using (在 C# 中) 或 Using (在 Visual Basic 中)。 如需詳細資訊,請參閱 IDisposable 介面文章中的<使用實作 IDisposable 的物件>一節。

對於以 .NET Framework 4.5.2 和更早版本為目標的應用程式,類別 X509Certificate 不會實 IDisposable 作 介面,因此沒有 Dispose 方法。

建構函式

X509Certificate()
已淘汰.

初始化 X509Certificate 類別的新執行個體。

X509Certificate(Byte[])

初始化 X509Certificate 類別的新執行個體 (這個類別是在表示 X.509v3 憑證的位元組序列中定義的)。

X509Certificate(Byte[], SecureString)

使用位元組陣列和密碼,初始化 X509Certificate 類別的新執行個體。

X509Certificate(Byte[], SecureString, X509KeyStorageFlags)

使用位元組陣列、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。

X509Certificate(Byte[], String)

使用位元組陣列和密碼,初始化 X509Certificate 類別的新執行個體。

X509Certificate(Byte[], String, X509KeyStorageFlags)

使用位元組陣列、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。

X509Certificate(IntPtr)

使用 Unmanaged PCCERT_CONTEXT 結構的控制代碼,初始化 X509Certificate 類別的新執行個體。

X509Certificate(SerializationInfo, StreamingContext)

使用 X509Certificate 物件和 SerializationInfo 結構,初始化 StreamingContext 類別的新執行個體。

X509Certificate(String)

使用 PKCS7 已簽署檔案的名稱,初始化 X509Certificate 類別的新執行個體。

X509Certificate(String, SecureString)

使用憑證檔名和密碼,初始化 X509Certificate 類別的新執行個體。

X509Certificate(String, SecureString, X509KeyStorageFlags)

使用憑證檔名、密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。

X509Certificate(String, String)

使用 PKCS7 已簽署檔案和用於存取憑證的密碼,初始化 X509Certificate 類別的新執行個體。

X509Certificate(String, String, X509KeyStorageFlags)

使用 PKCS7 已簽署檔案、用於存取憑證的密碼和金鑰儲存旗標,初始化 X509Certificate 類別的新執行個體。

X509Certificate(X509Certificate)

使用另一個 X509Certificate 類別,初始化 X509Certificate 類別的新執行個體。

屬性

Handle

取得 Unmanaged PCCERT_CONTEXT 結構所描述之 Microsoft Cryptographic API 憑證內容的控制代碼。

Issuer

取得核發 X.509v3 憑證的憑證授權單位名稱。

SerialNumberBytes

取得憑證序號的大端標記法。

Subject

取得憑證的主旨辨別名稱。

方法

CreateFromCertFile(String)

從指定的 PKCS7 已簽署檔案建立 X.509v3 憑證。

CreateFromSignedFile(String)

從指定簽名檔建立 X.509v3 憑證。

Dispose()

釋放由 X509Certificate 物件使用的所有資源。

Dispose(Boolean)

釋放這個 X509Certificate 使用的所有 Unmanaged 資源,並選擇性地釋放 Managed 資源。

Equals(Object)

比較兩個 X509Certificate 物件是否相等。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
Equals(X509Certificate)

比較兩個 X509Certificate 物件是否相等。

Export(X509ContentType)

以其中一個 X509Certificate 值所描述的格式,將目前的 X509ContentType 物件匯出至位元組陣列。

Export(X509ContentType, SecureString)

使用指定的格式和密碼,將目前的 X509Certificate 物件匯出至位元組陣列。

Export(X509ContentType, String)

以其中一個 X509Certificate 值所描述的格式,並使用指定的密碼,將目前的 X509ContentType 物件匯出至位元組陣列。

FormatDate(DateTime)

將指定的日期和時間轉換成字串。

GetCertHash()

將 X.509v3 憑證的雜湊值 (Hash Value) 傳回為位元組陣列。

GetCertHash(HashAlgorithmName)

傳回使用指定密碼編譯雜湊演算法所計算 X.509v3 憑證的雜湊值。

GetCertHashString()

將 X.509v3 憑證的 SHA1 雜湊值傳回為十六進位的字串。

GetCertHashString(HashAlgorithmName)

傳回包含使用指定密碼編譯雜湊演算法所計算 X.509v3 憑證雜湊值的十六進位字串。

GetEffectiveDateString()

傳回這個 X.509v3 憑證的有效日期。

GetExpirationDateString()

傳回這個 X.509v3 憑證的到期日。

GetFormat()

傳回這個 X.509v3 憑證的格式名稱。

GetHashCode()

將 X.509v3 憑證的雜湊程式碼傳回為整數。

GetIssuerName()
已淘汰.
已淘汰.
已淘汰.
已淘汰.

傳回發出 X.509v3 憑證的憑證授權單位名稱。

GetKeyAlgorithm()

傳回做為字串的這個 X.509v3 憑證金鑰演算法資訊。

GetKeyAlgorithmParameters()

傳回做為位元組陣列的 X.509v3 憑證金鑰演算法參數。

GetKeyAlgorithmParametersString()

傳回做為十六進位字串的 X.509v3 憑證金鑰演算法參數。

GetName()
已淘汰.
已淘汰.
已淘汰.
已淘汰.

返回已核發憑證的主要名稱。

GetPublicKey()

傳回做為位元組陣列的 X.509v3 憑證公開金鑰。

GetPublicKeyString()

傳回做為十六進位字串的 X.509v3 憑證公開金鑰。

GetRawCertData()

傳回做為位元組陣列的整個 X.509v3 憑證的未經處理資料。

GetRawCertDataString()

傳回做為十六進位字串的整個 X.509v3 憑證的未經處理資料。

GetSerialNumber()

傳回作為位元組由小到大順序之位元組陣列的 X.509v3 憑證序號。

GetSerialNumberString()

傳回作為位元組由小到大十六進位字串的 X.509v3 憑證序號。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
Import(Byte[])
已淘汰.

用位元組陣列的資料填入 X509Certificate 物件。

Import(Byte[], SecureString, X509KeyStorageFlags)
已淘汰.

使用位元組陣列的資料、密碼和金鑰儲存旗標,填入 X509Certificate 物件。

Import(Byte[], String, X509KeyStorageFlags)
已淘汰.

用位元組陣列的資料、密碼和用於判斷如何匯入私密金鑰的旗標,填入 X509Certificate 物件。

Import(String)
已淘汰.

用憑證檔的資訊填入 X509Certificate 物件。

Import(String, SecureString, X509KeyStorageFlags)
已淘汰.

用憑證檔的資訊、密碼和金鑰儲存旗標,填入 X509Certificate 物件。

Import(String, String, X509KeyStorageFlags)
已淘汰.

用憑證檔案的資訊、密碼和 X509Certificate 值,填入 X509KeyStorageFlags 物件。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Reset()

重設 X509Certificate2 物件的狀態。

ToString()

傳回目前 X509Certificate 物件的字串表示。

ToString(Boolean)

傳回目前 X509Certificate 物件的字串表示,如果指定,則附帶額外資訊。

TryGetCertHash(HashAlgorithmName, Span<Byte>, Int32)

使用所指定雜湊演算法來雜湊憑證的編碼表示,以嘗試產生憑證的「指紋」。

明確介面實作

IDeserializationCallback.OnDeserialization(Object)

實作 ISerializable 介面並在還原序列化完成時,由還原序列化事件回呼。

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

取得重新建立目前 X509Certificate 物件的執行個體所需之全部資料的序列化資訊。

適用於