System.Security.Cryptography.X509Certificates.X509Certificate2.Import Method

Populates an System.Security.Cryptography.X509Certificates.X509Certificate2 object using data from a byte array, a password, and flags for determining how to import the private key.

Syntax

[System.MonoTODO("missing KeyStorageFlags support")]
public override void Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)

Parameters

rawData
A byte array containing data from an X.509 certificate.
password
The password required to access the X.509 certificate data.
keyStorageFlags
A bitwise combination of the enumeration values that control where and how to import the certificate.

Remarks

This method can be used to populate an System.Security.Cryptography.X509Certificates.X509Certificate2 object using a password for the certificate represented by the byte array. The System.Security.Cryptography.X509Certificates.X509KeyStorageFlags value can be used to control where and how to import the private key.

This method accepts a byte array and can be used for certificate types such as Base64-encoded or DER-encoded X.509 certificates or PFX/PKCS12 certificates. Note that a PFX/PKCS12 certificate can contain more than one certificate. In that case, the first certificate associated with a private key is used or, if no private key is found, the first certificate is used.

Note:

Never hard code a password within your source code. Hard-coded passwords can be retrieved from an assembly using the MSIL Disassembler (Ildasm.exe), a hex editor, or by simply opening up the assembly in a text editor such as Notepad.exe.

Requirements

Namespace: System.Security.Cryptography.X509Certificates
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0