System.Security.Cryptography.X509Certificates.X509Certificate.Export Method

Exports the current System.Security.Cryptography.X509Certificates.X509Certificate object to a byte array in a format described by one of the System.Security.Cryptography.X509Certificates.X509ContentType values, and using the specified password.

Syntax

[System.Runtime.InteropServices.ComVisible(false)]
public virtual byte[] Export (X509ContentType contentType, string password)

Parameters

contentType
One of the System.Security.Cryptography.X509Certificates.X509ContentType values that describes how to format the output data.
password
The password required to access the X.509 certificate data.

Returns

An array of bytes that represents the current System.Security.Cryptography.X509Certificates.X509Certificate object.

Remarks

The contentType parameter accepts only the following values of the System.Security.Cryptography.X509Certificates.X509ContentType enumeration: X509ContentType.Cert, X509ContentType.SerializedCert, and X509ContentType.Pkcs12. Passing any other value causes a System.Security.Cryptography.CryptographicException to be thrown.

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 the assembly in a text editor such as Notepad.exe.

Requirements

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