X509Certificate2.Export(X509ContentType, String) Method

Definition

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

public:
 override cli::array <System::Byte> ^ Export(System::Security::Cryptography::X509Certificates::X509ContentType contentType, System::String ^ password);
public override byte[] Export (System.Security.Cryptography.X509Certificates.X509ContentType contentType, string password);
override this.Export : System.Security.Cryptography.X509Certificates.X509ContentType * string -> byte[]
Public Overrides Function Export (contentType As X509ContentType, password As String) As Byte()

Parameters

contentType
X509ContentType

One of the X509ContentType values that describes how to format the output data.

password
String

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

Returns

Byte[]

An array of bytes that represents the current X509Certificate object.

Exceptions

A value other than Cert, SerializedCert, or Pkcs12 was passed to the contentType parameter.

-or-

The certificate could not be exported.

Remarks

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

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) tool, a hex editor, or by simply opening the assembly in a text editor such as Notepad.exe.

Applies to