語言

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
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 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 。

Important

從 .NET Framework 4.6 開始,這種介面類型實現了。IDisposable 當您完成使用這個物品後,應直接或間接地處理它。 若要直接處置類型,請在 Disposetry/ 區塊中呼叫其 catch 方法。 若要間接處置它,請使用語言建構,例如 using (C#) 或 Using (在 Visual Basic 中)。 如需詳細資訊,請參閱介面主題中的 <使用實作 IDisposable 的物件>一節。

對於針對 .NET Framework 4.5.2 及更早版本的應用程式,該X509Certificate類別不實作介面IDisposable,因此沒有方法。Dispose

建構函式

名稱 Description
X509Certificate()
已淘汰.
已淘汰.

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

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

使用位元組陣列、密碼和金鑰儲存標誌初始化該類別的新 X509Certificate 實例。

X509Certificate(Byte[], SecureString)
已淘汰.

使用位元組陣列和密碼初始化該類別的新 X509Certificate 實例。

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

使用位元組陣列、密碼和金鑰儲存標誌初始化該類別的新 X509Certificate 實例。

X509Certificate(Byte[], String)
已淘汰.

使用位元組陣列和密碼初始化該類別的新 X509Certificate 實例。

X509Certificate(Byte[])
已淘汰.

初始化由代表 X.509v3 憑證的位元組序列定義的新 X509Certificate 類別實例。

X509Certificate(IntPtr)

使用一個代柄初始化該類別的新實例 X509Certificate ,並指向非受管理 PCCERT_CONTEXT 結構。

X509Certificate(SerializationInfo, StreamingContext)
已淘汰.

使用X509Certificate物件與SerializationInfo結構初始化類別的新實例StreamingContext。

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

使用憑證檔案名稱、密碼及金鑰儲存標誌初始化該類別的新 X509Certificate 實例。

X509Certificate(String, SecureString)
已淘汰.

使用憑證檔案名稱和密碼初始化該 X509Certificate 類別的新實例。

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

使用一個 PKCS7 簽署檔案的名稱、存取憑證的密碼,以及金鑰儲存標誌,初始化該 X509Certificate 類別的新實例。

X509Certificate(String, String)
已淘汰.

利用 PKCS7 簽署檔案名稱及密碼初始化該類別的新實例 X509Certificate 以存取憑證。

X509Certificate(String)
已淘汰.

使用 PKCS7 簽署檔案的名稱初始化該 X509Certificate 類別的新實例。

X509Certificate(X509Certificate)

初始化使用另一個X509Certificate類別的新實例X509Certificate。

屬性

名稱 Description
Handle

取得一個 Microsoft 密碼 API 憑證上下文的 handle,該上下文由非受管理 PCCERT_CONTEXT 結構描述。

Issuer

取得發行 X.509v3 證書的憑證授權機構名稱。

SerialNumberBytes

取得證書序號的大端表示。

Subject

從證書中取得主題的區別名稱。

方法

名稱 Description
CreateFromCertFile(String)
已淘汰.

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

CreateFromSignedFile(String)
已淘汰.

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

Dispose()

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

Dispose(Boolean)

釋放所有未管理資源, X509Certificate 並可選擇性地釋放受管理資源。

Equals(Object)

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

Equals(Object)

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

(繼承來源 Object)
Equals(X509Certificate)

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

Export(X509ContentType, SecureString)

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

Export(X509ContentType, String)

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

Export(X509ContentType)

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

ExportPkcs12(PbeParameters, String)

匯出憑證與私鑰,格式為 PKCS#12 / PFX。

ExportPkcs12(Pkcs12ExportPbeParameters, String)

匯出憑證與私鑰,格式為 PKCS#12 / PFX。

FormatDate(DateTime)

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

GetCertHash()

回傳 X.509v3 憑證的雜湊值,作為一個位元組陣列。

GetCertHash(HashAlgorithmName)

回傳 X.509v3 憑證的雜湊值,該值是使用指定的密碼學雜湊演算法計算出來的。

GetCertHashString()

以十六進位字串回傳 X.509v3 憑證的 SHA-1 雜湊值。

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[], SecureString, X509KeyStorageFlags)
已淘汰.
已淘汰.

透過位元組陣列、密碼及金鑰儲存標誌填充物件。X509Certificate

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

利用位元組陣列資料、密碼及標誌來填充 X509Certificate 物件,以決定私鑰的匯入方式。

Import(Byte[])
已淘汰.
已淘汰.

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

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

將憑證檔案、密碼及金鑰儲存旗標的資訊填充物件 X509Certificate 。

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

會將憑證檔案、密碼和X509Certificate一個值的資訊填充到X509KeyStorageFlags物件中。

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

會將憑證檔案中的資訊填充物件。X509Certificate

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
Reset()

重置物件的 X509Certificate2 狀態。

ToString()

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

ToString(Boolean)

回傳當前 X509Certificate 物件的字串表示,若指定並附有額外資訊。

TryGetCertHash(HashAlgorithmName, Span<Byte>, Int32)

嘗試透過將憑證的編碼表示與指定的雜湊演算法雜湊,產生憑證的「拇指指紋」。

明確介面實作

名稱 Description
IDeserializationCallback.OnDeserialization(Object)

實作介面 ISerializable ,當反序列化完成時,反序列事件會被呼叫回來。

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

取得序列化資訊,包含重建當前 X509Certificate 物件實例所需的所有資料。

適用於