X509Certificate.Import 方法

定義

填入 X509Certificate 物件。Populates an X509Certificate object.

多載

Import(Byte[])

用位元組陣列的資料填入 X509Certificate 物件。Populates the X509Certificate object with data from a byte array.

Import(String)

用憑證檔的資訊填入 X509Certificate 物件。Populates the X509Certificate object with information from a certificate file.

Import(Byte[], SecureString, X509KeyStorageFlags)

使用位元組陣列的資料、密碼和金鑰儲存旗標,填入 X509Certificate 物件。Populates an X509Certificate object using data from a byte array, a password, and a key storage flag.

Import(Byte[], String, X509KeyStorageFlags)

用位元組陣列的資料、密碼和用於判斷如何匯入私密金鑰的旗標,填入 X509Certificate 物件。Populates the X509Certificate object using data from a byte array, a password, and flags for determining how the private key is imported.

Import(String, SecureString, X509KeyStorageFlags)

用憑證檔的資訊、密碼和金鑰儲存旗標,填入 X509Certificate 物件。Populates an X509Certificate object with information from a certificate file, a password, and a key storage flag.

Import(String, String, X509KeyStorageFlags)

用憑證檔案的資訊、密碼和 X509Certificate 值,填入 X509KeyStorageFlags 物件。Populates the X509Certificate object with information from a certificate file, a password, and a X509KeyStorageFlags value.

Import(Byte[])

用位元組陣列的資料填入 X509Certificate 物件。Populates the X509Certificate object with data from a byte array.

public:
 virtual void Import(cli::array <System::Byte> ^ rawData);
[System.Runtime.InteropServices.ComVisible(false)]
[System.Security.SecurityCritical]
public virtual void Import (byte[] rawData);
abstract member Import : byte[] -> unit
override this.Import : byte[] -> unit
Public Overridable Sub Import (rawData As Byte())

參數

rawData
Byte[]

位元組陣列,包含來自 X.509 憑證的資料。A byte array containing data from an X.509 certificate.

屬性

例外狀況

rawData 參數為 nullThe rawData parameter is null.

-或--or- rawData 參數的長度為 0。The length of the rawData parameter is 0.

備註

這個方法可以用來接受 x.509 憑證的原始位元組陣列,並在 X509Certificate 物件中填入其相關聯的值。This method can be used to take the raw byte array of an X.509 certificate and populate the X509Certificate object with its associated values.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫者。requires full trust for the immediate caller. 這個類別無法由部分信任或透明的程式碼使用。This class cannot be used by partially trusted or transparent code.

InheritanceDemand
適用於繼承者的完全信任的。for full trust for inheritors. 部分信任的程式碼無法繼承這個成員。This member cannot be inherited by partially trusted code.

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

Import(String)

用憑證檔的資訊填入 X509Certificate 物件。Populates the X509Certificate object with information from a certificate file.

public:
 virtual void Import(System::String ^ fileName);
[System.Runtime.InteropServices.ComVisible(false)]
[System.Security.SecurityCritical]
public virtual void Import (string fileName);
abstract member Import : string -> unit
override this.Import : string -> unit
Public Overridable Sub Import (fileName As String)

參數

fileName
String

以字串表示的憑證檔名稱。The name of a certificate file represented as a string.

屬性

例外狀況

fileName 參數為 nullThe fileName parameter is null.

範例

下列範例會從檔案載入 x.509 憑證、呼叫 ToString 方法,並將結果顯示在主控台中。The following example loads an X.509 certificate from a file, calls the ToString method, and displays the results to the console.

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;
   cert->Import(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;


class X509
{

    static void Main()
    {

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

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

        cert.Import(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

        cert.Import(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

備註

這個方法會使用代表 x.509 憑證的憑證檔案(例如副檔名為 .cer 的檔案),並使用檔案包含的憑證填入 X509Certificate 物件。This method uses a certificate file (such as a file with a .cer extension) that represents an X.509 certificate, and populates the X509Certificate object with the certificate that the file contains.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫者。requires full trust for the immediate caller. 這個類別無法由部分信任或透明的程式碼使用。This class cannot be used by partially trusted or transparent code.

InheritanceDemand
適用於繼承者的完全信任的。for full trust for inheritors. 部分信任的程式碼無法繼承這個成員。This member cannot be inherited by partially trusted code.

FileIOPermission
讀取 fileName 參數所描述之檔案的許可權。for permission to read the file described by the fileName parameter. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: ReadAssociated enumeration: Read

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

Import(Byte[], SecureString, X509KeyStorageFlags)

重要

此 API 不符合 CLS 規範。

使用位元組陣列的資料、密碼和金鑰儲存旗標,填入 X509Certificate 物件。Populates an X509Certificate object using data from a byte array, a password, and a key storage flag.

public:
 virtual void Import(cli::array <System::Byte> ^ rawData, System::Security::SecureString ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public virtual void Import (byte[] rawData, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
abstract member Import : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
override this.Import : byte[] * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
Public Overridable Sub Import (rawData As Byte(), password As SecureString, keyStorageFlags As X509KeyStorageFlags)

參數

rawData
Byte[]

位元組陣列,包含來自 X.509 憑證的資料。A byte array that contains data from an X.509 certificate.

password
SecureString

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags

列舉值的位元組合,會控制匯入憑證的位置和方式。A bitwise combination of the enumeration values that control where and how to import the certificate.

屬性

例外狀況

rawData 參數為 nullThe rawData parameter is null.

-或--or- rawData 參數的長度為 0。The length of the rawData parameter is 0.

備註

重要

絕對不要在原始程式碼中將密碼硬編碼。Never hard code a password within your source code. 您可以使用 tlbimp.exe (IL解譯器)、十六進位編輯器,或直接在文字編輯器(如 notepad.exe)中開啟元件,從元件中取出硬式編碼密碼。Hard-coded passwords can be retrieved from an assembly using the Ildasm.exe (IL Disassembler), a hex editor, or by simply opening the assembly in a text editor such as Notepad.exe.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫者。requires full trust for the immediate caller. 這個類別無法由部分信任或透明的程式碼使用。This class cannot be used by partially trusted or transparent code.

InheritanceDemand
適用於繼承者的完全信任的。for full trust for inheritors. 部分信任的程式碼無法繼承這個成員。This member cannot be inherited by partially trusted code.

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

Import(Byte[], String, X509KeyStorageFlags)

用位元組陣列的資料、密碼和用於判斷如何匯入私密金鑰的旗標,填入 X509Certificate 物件。Populates the X509Certificate object using data from a byte array, a password, and flags for determining how the private key is imported.

public:
 virtual void Import(cli::array <System::Byte> ^ rawData, System::String ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
[System.Runtime.InteropServices.ComVisible(false)]
[System.Security.SecurityCritical]
public virtual void Import (byte[] rawData, string password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
abstract member Import : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
override this.Import : byte[] * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
Public Overridable Sub Import (rawData As Byte(), password As String, keyStorageFlags As X509KeyStorageFlags)

參數

rawData
Byte[]

位元組陣列,包含來自 X.509 憑證的資料。A byte array containing data from an X.509 certificate.

password
String

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags

列舉值的位元組合,會控制匯入憑證的位置和方式。A bitwise combination of the enumeration values that control where and how to import the certificate.

屬性

例外狀況

rawData 參數為 nullThe rawData parameter is null.

-或--or- rawData 參數的長度為 0。The length of the rawData parameter is 0.

備註

這個方法可以用來為位元組陣列所代表的憑證使用密碼來填入 X509Certificate 物件。This method can be used to populate an X509Certificate object using a password for the certificate represented by the byte array. X509KeyStorageFlags 值可用於控制匯入私密金鑰的位置和方式。The X509KeyStorageFlags value can be used to control where and how the private key is imported.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫者。requires full trust for the immediate caller. 這個類別無法由部分信任或透明的程式碼使用。This class cannot be used by partially trusted or transparent code.

InheritanceDemand
適用於繼承者的完全信任的。for full trust for inheritors. 部分信任的程式碼無法繼承這個成員。This member cannot be inherited by partially trusted code.

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

Import(String, SecureString, X509KeyStorageFlags)

重要

此 API 不符合 CLS 規範。

用憑證檔的資訊、密碼和金鑰儲存旗標,填入 X509Certificate 物件。Populates an X509Certificate object with information from a certificate file, a password, and a key storage flag.

public:
 virtual void Import(System::String ^ fileName, System::Security::SecureString ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public virtual void Import (string fileName, System.Security.SecureString password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
abstract member Import : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
override this.Import : string * System.Security.SecureString * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
Public Overridable Sub Import (fileName As String, password As SecureString, keyStorageFlags As X509KeyStorageFlags)

參數

fileName
String

憑證檔的名稱。The name of a certificate file.

password
SecureString

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags

列舉值的位元組合,會控制匯入憑證的位置和方式。A bitwise combination of the enumeration values that control where and how to import the certificate.

屬性

例外狀況

fileName 參數為 nullThe fileName parameter is null.

備註

重要

絕對不要在原始程式碼中將密碼硬編碼。Never hard code a password within your source code. 您可以使用 tlbimp.exe (IL解譯器)、十六進位編輯器,或直接在文字編輯器(如 notepad.exe)中開啟元件,從元件中取出硬式編碼密碼。Hard-coded passwords can be retrieved from an assembly using the Ildasm.exe (IL Disassembler), a hex editor, or by simply opening the assembly in a text editor such as Notepad.exe.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫者。requires full trust for the immediate caller. 這個類別無法由部分信任或透明的程式碼使用。This class cannot be used by partially trusted or transparent code.

InheritanceDemand
適用於繼承者的完全信任的。for full trust for inheritors. 部分信任的程式碼無法繼承這個成員。This member cannot be inherited by partially trusted code.

FileIOPermission
讀取 fileName 參數所描述之檔案的許可權。for permission to read the file described by the fileName parameter. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: ReadAssociated enumeration: Read

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

Import(String, String, X509KeyStorageFlags)

用憑證檔案的資訊、密碼和 X509Certificate 值,填入 X509KeyStorageFlags 物件。Populates the X509Certificate object with information from a certificate file, a password, and a X509KeyStorageFlags value.

public:
 virtual void Import(System::String ^ fileName, System::String ^ password, System::Security::Cryptography::X509Certificates::X509KeyStorageFlags keyStorageFlags);
[System.Runtime.InteropServices.ComVisible(false)]
[System.Security.SecurityCritical]
public virtual void Import (string fileName, string password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags);
abstract member Import : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
override this.Import : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags -> unit
Public Overridable Sub Import (fileName As String, password As String, keyStorageFlags As X509KeyStorageFlags)

參數

fileName
String

以字串表示的憑證檔名稱。The name of a certificate file represented as a string.

password
String

存取 X.509 憑證資料所需的密碼。The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags

列舉值的位元組合,會控制匯入憑證的位置和方式。A bitwise combination of the enumeration values that control where and how to import the certificate.

屬性

例外狀況

fileName 參數為 nullThe fileName parameter is null.

備註

重要

絕對不要以硬式編碼的程式碼在您的原始程式碼中撰寫密碼。Never hard-code a password within your source code. 您可以使用 tlbimp.exe (IL解譯器)、十六進位編輯器,或直接在文字編輯器(如 notepad.exe)中開啟元件,從元件中取出硬式編碼密碼。Hard-coded passwords can be retrieved from an assembly using the Ildasm.exe (IL Disassembler), a hex editor, or by simply opening the assembly in a text editor such as Notepad.exe.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫者。requires full trust for the immediate caller. 這個類別無法由部分信任或透明的程式碼使用。This class cannot be used by partially trusted or transparent code.

InheritanceDemand
適用於繼承者的完全信任的。for full trust for inheritors. 部分信任的程式碼無法繼承這個成員。This member cannot be inherited by partially trusted code.

FileIOPermission
讀取 fileName 參數所描述之檔案的許可權。for permission to read the file described by the fileName parameter. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: ReadAssociated enumeration: Read

KeyContainerPermission
建立金鑰容器的許可權。for permission to create a key container. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉: CreateAssociated enumeration: Create

適用於