X509Certificate.Import X509Certificate.Import X509Certificate.Import X509Certificate.Import Method

Definition

Populates an X509Certificate object.

Overloads

Import(Byte[]) Import(Byte[]) Import(Byte[]) Import(Byte[])

Populates the X509Certificate object with data from a byte array.

Import(String) Import(String) Import(String) Import(String)

Populates the X509Certificate object with information from a certificate file.

Import(Byte[], SecureString, X509KeyStorageFlags) Import(Byte[], SecureString, X509KeyStorageFlags) Import(Byte[], SecureString, X509KeyStorageFlags) Import(Byte[], SecureString, X509KeyStorageFlags)

Populates an X509Certificate object using data from a byte array, a password, and a key storage flag.

Import(Byte[], String, X509KeyStorageFlags) Import(Byte[], String, X509KeyStorageFlags) Import(Byte[], String, X509KeyStorageFlags) Import(Byte[], String, X509KeyStorageFlags)

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) Import(String, SecureString, X509KeyStorageFlags) Import(String, SecureString, X509KeyStorageFlags) Import(String, SecureString, X509KeyStorageFlags)

Populates an X509Certificate object with information from a certificate file, a password, and a key storage flag.

Import(String, String, X509KeyStorageFlags) Import(String, String, X509KeyStorageFlags) Import(String, String, X509KeyStorageFlags) Import(String, String, X509KeyStorageFlags)

Populates the X509Certificate object with information from a certificate file, a password, and a X509KeyStorageFlags value.

Import(Byte[]) Import(Byte[]) Import(Byte[]) Import(Byte[])

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())

Parameters

rawData
Byte[]

A byte array containing data from an X.509 certificate.

Exceptions

The rawData parameter is null.

-or-

The length of the rawData parameter is 0.

Remarks

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.

Security

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. Security action: Demand. Associated enumeration: Create

Import(String) Import(String) Import(String) Import(String)

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)

Parameters

fileName
String String String String

The name of a certificate file represented as a string.

Exceptions

Examples

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

Remarks

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.

Security

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
for permission to read the file described by the fileName parameter. Security action: Demand. Associated enumeration: Read

KeyContainerPermission
for permission to create a key container. Security action: Demand. Associated enumeration: Create

Import(Byte[], SecureString, X509KeyStorageFlags) Import(Byte[], SecureString, X509KeyStorageFlags) Import(Byte[], SecureString, X509KeyStorageFlags) Import(Byte[], SecureString, X509KeyStorageFlags)

Important

This API is not CLS-compliant.

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)

Parameters

rawData
Byte[]

A byte array that contains data from an X.509 certificate.

password
SecureString SecureString SecureString SecureString

The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags X509KeyStorageFlags X509KeyStorageFlags X509KeyStorageFlags

A bitwise combination of the enumeration values that control where and how to import the certificate.

Exceptions

The rawData parameter is null.

-or-

The length of the rawData parameter is 0.

Remarks

Important

Never hard code a password within your source code. 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.

Security

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. Security action: Demand. Associated enumeration: Create

Import(Byte[], String, X509KeyStorageFlags) Import(Byte[], String, X509KeyStorageFlags) Import(Byte[], String, X509KeyStorageFlags) Import(Byte[], String, X509KeyStorageFlags)

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)

Parameters

rawData
Byte[]

A byte array containing data from an X.509 certificate.

password
String String String String

The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags X509KeyStorageFlags X509KeyStorageFlags X509KeyStorageFlags

A bitwise combination of the enumeration values that control where and how to import the certificate.

Exceptions

The rawData parameter is null.

-or-

The length of the rawData parameter is 0.

Remarks

This method can be used to populate an X509Certificate object using a password for the certificate represented by the byte array. The X509KeyStorageFlags value can be used to control where and how the private key is imported.

Security

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. Security action: Demand. Associated enumeration: Create

Import(String, SecureString, X509KeyStorageFlags) Import(String, SecureString, X509KeyStorageFlags) Import(String, SecureString, X509KeyStorageFlags) Import(String, SecureString, X509KeyStorageFlags)

Important

This API is not CLS-compliant.

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)

Parameters

fileName
String String String String

The name of a certificate file.

password
SecureString SecureString SecureString SecureString

The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags X509KeyStorageFlags X509KeyStorageFlags X509KeyStorageFlags

A bitwise combination of the enumeration values that control where and how to import the certificate.

Exceptions

Remarks

Important

Never hard code a password within your source code. 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.

Security

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
for permission to read the file described by the fileName parameter. Security action: Demand. Associated enumeration: Read

KeyContainerPermission
for permission to create a key container. Security action: Demand. Associated enumeration: Create

Import(String, String, X509KeyStorageFlags) Import(String, String, X509KeyStorageFlags) Import(String, String, X509KeyStorageFlags) Import(String, String, 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)

Parameters

fileName
String String String String

The name of a certificate file represented as a string.

password
String String String String

The password required to access the X.509 certificate data.

keyStorageFlags
X509KeyStorageFlags X509KeyStorageFlags X509KeyStorageFlags X509KeyStorageFlags

A bitwise combination of the enumeration values that control where and how to import the certificate.

Exceptions

Remarks

Important

Never hard-code a password within your source code. 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.

Security

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
for permission to read the file described by the fileName parameter. Security action: Demand. Associated enumeration: Read

KeyContainerPermission
for permission to create a key container. Security action: Demand. Associated enumeration: Create

Applies to