# CertMgr Component

The CertMgr component is used to create, read, and manage certificates.

## Syntax

```text
nsoftware.PDFSDK.CertMgr
```

## Remarks

The component methods, such as [ListCertificateStores](#listcertificatestores-method-certmgr-component) or [ListStoreCertificates](#liststorecertificates-method-certmgr-component), are used to list certificate stores and certificates. The corresponding lists are returned through the [StoreList](#storelist-event-certmgr-component) and [CertList](#certlist-event-certmgr-component) events. Encoded certificates are provided through the events.

You can load a certificate by setting the [Cert](#cert-property-certmgr-component) property of the component. Then you can get information about the certificate through the corresponding fields of the [Cert](#cert-property-certmgr-component) property (described below).

The [Subject](#Certificate_f_Subject), [SerialNumber](#Certificate_f_SerialNumber), and [Issuer](#Certificate_f_Issuer) fields identify the certificate. The [EffectiveDate](#Certificate_f_EffectiveDate) and [ExpirationDate](#Certificate_f_ExpirationDate) show the time boundaries of the certificate.

[PublicKey](#Certificate_f_PublicKey), [PublicKeyAlgorithm](#Certificate_f_PublicKeyAlgorithm), [PublicKeyLength](#Certificate_f_PublicKeyLength), and [Version](#Certificate_f_Version) provide information about the certificate keys and the certificate format (version).

[UsageFlags](#Certificate_f_UsageFlags) specifies the intended usage of the certificate. The [Usage](#Certificate_f_Usage) field provides a text description of these flags.

## Property List

*The following is the full list of the properties of the component with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [Cert](#cert-property-certmgr-component) | This is the currently selected certificate. |
| [CertExtensions](#certextensions-property-certmgr-component) | This is a list of extensions used by the currently selected certificate. |
| [CertStore](#certstore-property-certmgr-component) | This is the certificate store to search for certificates. |
| [CertStorePassword](#certstorepassword-property-certmgr-component) | This is the password for the certificate store (if any). |
| [CertStoreType](#certstoretype-property-certmgr-component) | This is the type of certificate store for [CertStore](#certstore-property-certmgr-component) . |
| [ExportedCert](#exportedcert-property-certmgr-component) | This is the exported certificate string. |
| [ExportFormat](#exportformat-property-certmgr-component) | This is the format to which the certificate is exported. |
| [ExportPrivateKey](#exportprivatekey-property-certmgr-component) | This controls whether to export the private key. |

## Method List

*The following is the full list of the methods of the component with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [CheckCRL](#checkcrl-method-certmgr-component) | This method checks the Certificate Revocation List (CRL) specified by the currently loaded certificate. |
| [CheckOCSP](#checkocsp-method-certmgr-component) | This method uses Online Certificate Status Protocol (OCSP) to check the status of the currently loaded certificate. |
| [Config](#config-method-certmgr-component) | Sets or retrieves a configuration setting. |
| [CreateCertificate](#createcertificate-method-certmgr-component) | This method creates a new self-signed certificate in the current store. |
| [CreateKey](#createkey-method-certmgr-component) | This method creates a new keyset associated with the provided name. |
| [DeleteCertificate](#deletecertificate-method-certmgr-component) | This method deletes the currently selected certificate from the store. |
| [DeleteKey](#deletekey-method-certmgr-component) | This method deletes the keyset associated with the provided name. |
| [ExportCertificate](#exportcertificate-method-certmgr-component) | This method exports the currently selected certificate. |
| [GenerateCSR](#generatecsr-method-certmgr-component) | This method generates a new Certificate Signing Request (CSR) to be sent to a signing authority. |
| [ImportCertificate](#importcertificate-method-certmgr-component) | This method imports a certificate from a file into the current certificate store. |
| [ImportSignedCSR](#importsignedcsr-method-certmgr-component) | This method imports a signed Certificate Signing Request (CSR). |
| [IssueCertificate](#issuecertificate-method-certmgr-component) | This creates a new certificate in the current store and is signed by the selected certificate. |
| [ListCertificateStores](#listcertificatestores-method-certmgr-component) | This lists the certificate stores. |
| [ListKeys](#listkeys-method-certmgr-component) | This lists the keysets in a Cryptographic Service Provider (CSP). |
| [ListMachineStores](#listmachinestores-method-certmgr-component) | This lists the machine certificate stores. |
| [ListStoreCertificates](#liststorecertificates-method-certmgr-component) | This lists the certificates in a store. |
| [ReadCertificate](#readcertificate-method-certmgr-component) | This loads a certificate from a file. |
| [ReadCSR](#readcsr-method-certmgr-component) | This reads a Certificate Signing Request (CSR). |
| [Reset](#reset-method-certmgr-component) | This resets all certificate properties to their default values. |
| [SaveCertificate](#savecertificate-method-certmgr-component) | This method saves the currently selected public certificate to a file. |
| [ShowCertificateChain](#showcertificatechain-method-certmgr-component) | This shows the certificate chain. |
| [SignCSR](#signcsr-method-certmgr-component) | This creates a signed certificate from a Certificate Signing Request (CSR). |

## Event List

*The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [CertChain](#certchain-event-certmgr-component) | This event shows the certificate chain for the certificate (see the [ShowCertificateChain](#showcertificatechain-method-certmgr-component) method). |
| [CertList](#certlist-event-certmgr-component) | This event lists the certificates in a store (see the [ListStoreCertificates](#liststorecertificates-method-certmgr-component) method). |
| [Error](#error-event-certmgr-component) | Fired when information is available about errors during data delivery. |
| [KeyList](#keylist-event-certmgr-component) | This lists the keysets in a Cryptographic Service Provider (CSP); see the [ListKeys](#listkeys-method-certmgr-component) method. |
| [Log](#log-event-certmgr-component) | This event fires once for each log message. |
| [StoreList](#storelist-event-certmgr-component) | This lists the system certificate stores (see the [ListCertificateStores](#listcertificatestores-method-certmgr-component) and [ListMachineStores](#listmachinestores-method-certmgr-component) methods). |

## Config Settings

*The following is a list of config settings for the component with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [BasicConstraints](#BasicConstraints) | The hex-encoded value of the certificate's Basic Constraints extension. |
| [CertComment](#CertComment) | A comment to include in a saved certificate. |
| [CertExtendedKeyUsage](#CertExtendedKeyUsage) | The extended key usage of the certificate. |
| [CertIssuerCertURL](#CertIssuerCertURL) | The URL where the issuing CA certificate can be obtained. |
| [CertKeyLength](#CertKeyLength) | The public key length for created certificates and keys. |
| [CertKeyType](#CertKeyType) | The types of keys created for new certificates. |
| [CertPublicKeyAlgorithm](#CertPublicKeyAlgorithm) | The public key algorithm used when a certificate is created. |
| [CertSignatureAlgorithm](#CertSignatureAlgorithm) | The signature algorithm used when creating certificates. |
| [CertSubjectAltNames](#CertSubjectAltNames) | Subject Alternative Names for creating or issuing certificates. |
| [CertUsageFlags](#CertUsageFlags) | Sets the flags indicating the usage of the created certificate. |
| [CertValidityOffset](#CertValidityOffset) | The number of days until the certificate becomes valid. |
| [CertValidityTime](#CertValidityTime) | The validity period for the certificate. |
| [CreatedKey](#CreatedKey) | The PKCS8 formatted private and public key pair created after calling CreateKey. |
| [CSP](#CSP) | The Cryptographic Service Provider. |
| [CSRKey](#CSRKey) | The PKCS8 formatted private key to use when generating a CSR. |
| [EncodeExportedCert](#EncodeExportedCert) | Whether the certificate being exported to a string is encoded. |
| [HasCRL](#HasCRL) | Whether the certificate supports the CRL extension. |
| [HasOCSP](#HasOCSP) | Whether the certificate supports the OCSP extension. |
| [ImportCertAction](#ImportCertAction) | Specified the action to take if a matching certificate or a link to a matching certificate already exists. |
| [ImportCertStoreType](#ImportCertStoreType) | The type of certificate store being specified for import. |
| [JWKAlgorithm](#JWKAlgorithm) | The JWK algorithm. |
| [JWKExportX5C](#JWKExportX5C) | Whether to export a certificate chain to the x5c parameter. |
| [JWKKeyId](#JWKKeyId) | The JWK key Id. |
| [JWKKeyOps](#JWKKeyOps) | The JWK intended key operations list. |
| [JWKUse](#JWKUse) | The JWK use parameter value. |
| [KeyFormat](#KeyFormat) | How the public and private key are formatted. |
| [KSP](#KSP) | The Key Storage Provider. |
| [LogLevel](#LogLevel) | The level of detail that is logged. |
| [PFXCertEncryptionAlgorithm](#PFXCertEncryptionAlgorithm) | Certificate encryption algorithm used when exporting to PFX format. |
| [PFXKeyEncryptionAlgorithm](#PFXKeyEncryptionAlgorithm) | Private key encryption algorithm used when exporting to PFX format. |
| [ReplaceKey](#ReplaceKey) | Whether or not to replace an existing key when creating a new key. |
| [RequestSubjectAltNames](#RequestSubjectAltNames) | Subject Alternative Names for a Certificate Signing Request. |
| [TPMMigrationPassword](#TPMMigrationPassword) | The password for the certificate or key. |
| [X509Algorithm](#X509Algorithm) | Public Key Algorithm OID. |
| [X509SignatureAlgorithm](#X509SignatureAlgorithm) | Signature Algorithm OID. |
| [BuildInfo](#BuildInfo) | Information about the product's build. |
| [GUIAvailable](#GUIAvailable) | Whether or not a message loop is available for processing events. |
| [LicenseInfo](#LicenseInfo) | Information about the current license. |
| [MaskSensitiveData](#MaskSensitiveData) | Whether sensitive data is masked in log messages. |
| [UseInternalSecurityAPI](#UseInternalSecurityAPI) | Whether or not to use the system security libraries or an internal implementation. |

# Cert Property ([CertMgr](#certmgr-component) Component)

This is the currently selected certificate.

## Syntax

```text
public Certificate Cert { get; set; }
```

## Remarks

This property is populated when a specified certificate is found or loaded by the component. It is used to specify private or public keys. Set this property to a valid [Certificate](#certificate-type) object to load a certificate and perform different operations, such as [DeleteCertificate](#deletecertificate-method-certmgr-component) or [ExportCertificate](#exportcertificate-method-certmgr-component).

 Please refer to the [Certificate](#certificate-type) type for a complete list of fields.

# CertExtensions Property ([CertMgr](#certmgr-component) Component)

This is a list of extensions used by the currently selected certificate.

## Syntax

```text
public CertExtensionList CertExtensions { get; }
```

## Remarks

This property contains a list of extensions used by the currently selected certificate. When [Cert](#cert-property-certmgr-component) is set, the component will read out any [CertExtension](#certextension-type) and populate this list. This list also may be populated by the user before a call to [CreateCertificate](#createcertificate-method-certmgr-component) to add certificate extensions to the certificate to be created.

This property is not available at design time.

 Please refer to the [CertExtension](#certextension-type) type for a complete list of fields.

# CertStore Property ([CertMgr](#certmgr-component) Component)

This is the certificate store to search for certificates.

## Syntax

```text
public string CertStore { get; set; }
public byte[] CertStoreB { get; set; }
```

## Default Value

"MY"

## Remarks

The [CertStoreType](#certstoretype-property-certmgr-component) property specifies the type of the certificate store specified by CertStore. If the store is password protected, specify the password in [CertStorePassword](#certstorepassword-property-certmgr-component).

 Designations of certificate stores are platform dependent.

The following designations are the most common User and Machine certificate stores in Windows:

|  |  |
| --- | --- |
| MY | A certificate store holding personal certificates with their associated private keys. |
| CA | Certifying authority certificates. |
| ROOT | Root certificates. |

When the certificate store type is *cstPFXFile*, this property must be set to the name of the file. When the type is *cstPFXBlob*, the property must be set to the binary contents of a PFX file (i.e., PKCS#12 certificate store).

# CertStorePassword Property ([CertMgr](#certmgr-component) Component)

This is the password for the certificate store (if any).

## Syntax

```text
public string CertStorePassword { get; set; }
```

## Default Value

""

## Remarks

The value of this property is used to open the certificate store if the certificate store requires a password.

# CertStoreType Property ([CertMgr](#certmgr-component) Component)

This is the type of certificate store for [CertStore](#certstore-property-certmgr-component) .

## Syntax

```text
public CertStoreTypes CertStoreType { get; set; }
enum CertMgrCertStoreTypes {
  cstUser,
  cstMachine,
  cstPFXFile,
  cstPFXBlob,
  cstJKSFile,
  cstJKSBlob,
  cstPEMKeyFile,
  cstPEMKeyBlob,
  cstPublicKeyFile,
  cstPublicKeyBlob,
  cstSSHPublicKeyBlob,
  cstP7BFile,
  cstP7BBlob,
  cstSSHPublicKeyFile,
  cstPPKFile,
  cstPPKBlob,
  cstXMLFile,
  cstXMLBlob,
  cstJWKFile,
  cstJWKBlob,
  cstSecurityKey,
  cstBCFKSFile,
  cstBCFKSBlob,
  cstPKCS11,
  cstAuto
}
```

## Default Value

0

## Remarks

The component supports both public and private keys in a variety of formats. When the *cstAuto* value is used, the component will automatically determine the type. This field can take one of the following values:

|  |  |
| --- | --- |
| 0 (cstUser - default) | For Windows, this specifies that the certificate store is a certificate store owned by the current user. NOTE: This store type is not available in Java. |
| 1 (cstMachine) | For Windows, this specifies that the certificate store is a machine store. NOTE: This store type is not available in Java. |
| 2 (cstPFXFile) | The certificate store is the name of a PFX (PKCS#12) file containing certificates. |
| 3 (cstPFXBlob) | The certificate store is a string (binary or Base64-encoded) representing a certificate store in PFX (PKCS#12) format. |
| 4 (cstJKSFile) | The certificate store is the name of a Java Key Store (JKS) file containing certificates. NOTE: This store type is only available in Java. |
| 5 (cstJKSBlob) | The certificate store is a string (binary or Base64-encoded) representing a certificate store in Java Key Store (JKS) format. NOTE: This store type is only available in Java. |
| 6 (cstPEMKeyFile) | The certificate store is the name of a PEM-encoded file that contains a private key and an optional certificate. |
| 7 (cstPEMKeyBlob) | The certificate store is a string (binary or Base64-encoded) that contains a private key and an optional certificate. |
| 8 (cstPublicKeyFile) | The certificate store is the name of a file that contains a PEM- or DER-encoded public key certificate. |
| 9 (cstPublicKeyBlob) | The certificate store is a string (binary or Base64-encoded) that contains a PEM- or DER-encoded public key certificate. |
| 10 (cstSSHPublicKeyBlob) | The certificate store is a string (binary or Base64-encoded) that contains an SSH-style public key. |
| 11 (cstP7BFile) | The certificate store is the name of a PKCS#7 file containing certificates. |
| 12 (cstP7BBlob) | The certificate store is a string (binary) representing a certificate store in PKCS#7 format. |
| 13 (cstSSHPublicKeyFile) | The certificate store is the name of a file that contains an SSH-style public key. |
| 14 (cstPPKFile) | The certificate store is the name of a file that contains a PPK (PuTTY Private Key). |
| 15 (cstPPKBlob) | The certificate store is a string (binary) that contains a PPK (PuTTY Private Key). |
| 16 (cstXMLFile) | The certificate store is the name of a file that contains a certificate in XML format. |
| 17 (cstXMLBlob) | The certificate store is a string that contains a certificate in XML format. |
| 18 (cstJWKFile) | The certificate store is the name of a file that contains a JWK (JSON Web Key). |
| 19 (cstJWKBlob) | The certificate store is a string that contains a JWK (JSON Web Key). |
| 21 (cstBCFKSFile) | The certificate store is the name of a file that contains a BCFKS (Bouncy Castle FIPS Key Store). NOTE: This store type is only available in Java and .NET. |
| 22 (cstBCFKSBlob) | The certificate store is a string (binary or Base64-encoded) representing a certificate store in BCFKS (Bouncy Castle FIPS Key Store) format. NOTE: This store type is only available in Java and .NET. |
| 23 (cstPKCS11) | The certificate is present on a physical security key accessible via a PKCS#11 interface. To use a security key, create a new [Certificate](#certificate-type) object and pass cstPKCS11 as the [StoreType](#Certificate_f_StoreType), the full path of the PKCS#11 DLL as the [Store](#Certificate_f_Store), and the PIN as the [StorePassword](#Certificate_f_StorePassword). Code Example. SSH Authentication with Security Key (without CertMgr): sftp.SSHCert = new Certificate(CertStoreTypes.cstPKCS11, @"C:\Program Files\OpenSC Project\OpenSC\pkcs11\opensc-pkcs11.dll", "123456", // PIN "CN=cert_subject"); sftp.SSHUser = "test"; sftp.SSHLogon("myhost", 22); Alternatively, collect the necessary data using the [CertMgr](#certmgr-component) component by calling the [ListStoreCertificates](#liststorecertificates-method-certmgr-component) method after setting the corresponding properties accordingly. The certificate information returned in the [CertList](#certlist-event-certmgr-component) event's CertEncoded parameter may be saved for later use. When using a certificate obtained with this approach, pass the previously saved security key information as the [Store](#Certificate_f_Store) and set [StorePassword](#Certificate_f_StorePassword) to the PIN. Code Example. SSH Authentication with Security Key (with CertMgr): certmgr.CertStoreType = CertStoreTypes.cstPKCS11; certmgr.OnCertList += (s, e) => { secKeyBlob = e.CertEncoded; }; certmgr.CertStore = @"C:\Program Files\OpenSC Project\OpenSC\pkcs11\opensc-pkcs11.dll"; certmgr.CertStorePassword = "123456"; // PIN certmgr.ListStoreCertificates(); sftp.SSHCert = new Certificate(CertStoreTypes.cstPKCS11, secKeyBlob, "123456", "*"); sftp.SSHUser = "test"; sftp.SSHLogon("myhost", 22); |
| 99 (cstAuto) | The store type is automatically detected from the input data. This setting may be used with both public and private keys and can detect any of the supported formats automatically. |

# ExportedCert Property ([CertMgr](#certmgr-component) Component)

This is the exported certificate string.

## Syntax

```text
public string ExportedCert { get; }
public byte[] ExportedCertB { get; }
```

## Default Value

""

## Remarks

This property holds the exported certificate if it was not exported to a file.

When calling [ExportCertificate](#exportcertificate-method-certmgr-component) if the *CertFile* parameter is an empty string, the certificate will be exported as a string and available in this property. This allows certificate data to be exported without writing any data to disk.

When [ExportFormat](#exportformat-property-certmgr-component) is set to *PFX* or *P7B*, the [EncodeExportedCert](#EncodeExportedCert) setting controls whether the value is binary or Base64 encoded.

This property is read-only and not available at design time.

# ExportFormat Property ([CertMgr](#certmgr-component) Component)

This is the format to which the certificate is exported.

## Syntax

```text
public string ExportFormat { get; set; }
```

## Default Value

"PFX"

## Remarks

ExportFormat is applicable when [ExportCertificate](#exportcertificate-method-certmgr-component) is called and may be used to specify the output format. The applicability of each format depends on whether [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is set. Some formats are applicable only when exporting to a private key and some values are applicable only when exporting to a public key.

```text
-----BEGIN CERTIFICATE-----
MIIBkTCB+6ADAgECAgEBMA0GCSqGSIb3DQEBBQUAMA4xDDAKBgNVBAMTAzEwMDAgFw0wNzAx
...
Pg49SpQ+HcUibIpum2O0hmnySH7BPGfXD8Lu
-----END CERTIFICATE-----
```

```text
-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQD5/STHUd7YkN1JyoyYnUvCf+Fyx1+ZleBJxvwDcm3yaZ98bvry
...
91y8ydb3mQ9l1hZudo2sj8tHnvEgph0r7B8hMM6Qaw==
-----END RSA PRIVATE KEY-----
```

```text
-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBALAyxV5assz+9v7aHbj93NYN5uGB/1z7kb2Nx4hj02QyRYbcD4htkhK4Qcq2GCsG
...
MxW4+pdeN4oEZ6rbMZt01bvMwNRX2GDEyQBhAgMBAAE=
-----END RSA PUBLIC KEY-----
```

```text
-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQD5/STHUd7YkN1JyoyYnUvCf+Fyx1+ZleBJxvwDcm3yaZ98bvry
...
91y8ydb3mQ9l1hZudo2sj8tHnvEgph0r7B8hMM6Qaw==
-----END RSA PRIVATE KEY-----
```

```text
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxdTNtpJQbw90cq6aJEx5vRIBrAiCAB9/F
...
8UdUliXeU8UGYjVcMhGy5oPsVeBXGcPAqF2mjXdBKNnzlSlctOLnYRBS5jwRuNfTQQIDAQAB
-----END PUBLIC KEY-----
```

```text
-----BEGIN PRIVATE KEY-----
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAPn9JMdR3tiQ3UnK
...
HSvsHyEwzpBr
-----END PRIVATE KEY-----
```

```text
ssh-rsa AAAAB3NzaC1y...
```

```text
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAlwAAAAdzc2gtcnNh
...
AwQFBgcICQo=
-----END OPENSSH PRIVATE KEY-----
```

```text
PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: rsa-key-20180822
Public-Lines: 4
AAAAB3NzaC1yc2EAAAADAQABAAAAgQCmz5j5kWUKxfwiv6J0LQ4wN9ekpeORXVaP
...
8pSSWejQ5Q==
Private-Lines: 8
AAAAgH87Sp/YcSw1dKoAZuWb0/2dKkKwMRIYEkS15caRpzAteay6WWX7l1sgBTU7
...
Oa0=
Private-MAC: d53e24f44bde8d1d3844a142fbb1fa7c88ea3585
```

```text
---- BEGIN SSH2 PUBLIC KEY ----
AAAAB3NzaC1yc2EAAAADAQABAAAAgQD5/STHUd7YkN1JyoyYnUvCf+Fyx1+ZleBJxvwDcm3y
...
6bVPTODELil1PVWJDlfdwoLZZKY2ACFHzxBqaOlYv1rbd2JIYAuqGca2ow==
---- END SSH2 PUBLIC KEY ----
```

```text
---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----
AAAAB3NzaC1yc2EAAAADAQABAAAAgQD5/STHUd7YkN1JyoyYnUvCf+Fyx1+ZleBJxvwDcm3y
...
6bVPTODELil1PVWJDlfdwoLZZKY2ACFHzxBqaOlYv1rbd2JIYAuqGca2ow==
---- END SSH2 ENCRYPTED PRIVATE KEY ----
```

```text
{
	"kty": "EC",
	"crv": "P-256",
	"x": "M_P_uqzP43FYW-kXWlpEDlX3nPZUr1QaMllAxUnao7w",
	"y": "zRFhp7iCXYIoTgerQ4LjGPTujodlimrwIMk-3enj_1Q"
}
```

```text
{
	"kty": "EC",
	"crv": "P-256",
	"x": "M_P_uqzP43FYW-kXWlpEDlX3nPZUr1QaMllAxUnao7w",
	"y": "zRFhp7iCXYIoTgerQ4LjGPTujodlimrwIMk-3enj_1Q",
	"d": "eFBtl-uaB9Y4b-CIav5IYX4gGRFBvpBmrMOOQ7L-euI"
}
```

```text
<X509Data>
	<X509Certificate>MIIB...D8Lu</X509Certificate>
</X509Data>
```

```text
<RSAKeyValue>
	<Modulus>+f0k...tqM=</Modulus>
	<Exponent>AQAB</Exponent>
	<P>/cOnF...tGw==</P>
	<Q>/DD5...dGQ==</Q>
	<DP>d75...N0w==</DP>
	<DQ>Cyv...rKQ==</DQ>
	<InverseQ>fsB...Qaw==</InverseQ>
	<D>J7p...YJE=</D>
</RSAKeyValue>
```

| ExportFormat | Applicability | Description |
| --- | --- | --- |
| "PFX" or "PKCS12" (default) | Private Keys | A PFX file (PKCS12). |
| "PEM" | Public and Private Keys | A PEM-formatted public certificate (X509/PKCS1/PKCS8), or PEM formatted private key (PKCS1/PKCS8). When [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False the exported certificate will be a PEM formatted X509 public certificate if the certificate being exported includes X509 data. If no X509 information is present, the public key will be exported in PKCS1 public key format for RSA/DSA keys and PKCS8 public key format for ECDSA/EdDSA keys. When [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True the exported certificate will be a PEM-formatted PKCS1 private key for RSA/DSA keys and a PEM-formatted PKCS8 private key for ECDSA/EdDSA keys. For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: Example when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |
| "PKCS1" | Public and Private Keys | A PEM-formatted PKCS1 key file. For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: Example when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |
| "PKCS8" | Public and Private Keys | A PEM-formatted PKCS8 key file. Example when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: Example when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |
| "OpenSSH" | Public and Private Keys | An OpenSSH public or private key file. For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: Example when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |
| "PPK" | Private Keys | A PuTTY private key file. For example, |
| "SSH2PublicKey" | Public Keys | An SSH2 public key. For example, |
| "SSH2PrivateKey" | Private Keys | An SSH2 private key. For example, |
| "JWK" | Private and Public Keys | A JSON Web Key (JWK). For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |
| "XML" | Private and Public Keys | An XML file holding the key or X509 data. For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |

# ExportPrivateKey Property ([CertMgr](#certmgr-component) Component)

This controls whether to export the private key.

## Syntax

```text
public bool ExportPrivateKey { get; set; }
```

## Default Value

True

## Remarks

This property controls whether the private key is exported when [ExportCertificate](#exportcertificate-method-certmgr-component) is called.

If set to True (default), the private key is exported. If set to False, only the public key is exported.

# CheckCRL Method ([CertMgr](#certmgr-component) Component)

This method checks the Certificate Revocation List (CRL) specified by the currently loaded certificate.

## Syntax

```text
public void CheckCRL();

Async Version
public async Task CheckCRL();
public async Task CheckCRL(CancellationToken cancellationToken);
```

## Remarks

This method will check the CRLs specified by the currently loaded [Cert](#cert-property-certmgr-component).

The component will first obtain the list of CRL URLs from the certificate's CRL distribution points extension. The component will then make HTTP requests to each CRL endpoint to check the validity of the certificate.

If the certificate has been revoked or any other issues are found during validation, the component throws an exception. To check whether the certificate supports the CRL extension, use the [HasCRL](#HasCRL) configuration setting.

# CheckOCSP Method ([CertMgr](#certmgr-component) Component)

This method uses Online Certificate Status Protocol (OCSP) to check the status of the currently loaded certificate.

## Syntax

```text
public void CheckOCSP();

Async Version
public async Task CheckOCSP();
public async Task CheckOCSP(CancellationToken cancellationToken);
```

## Remarks

This method will use OCSP to check the validity of the currently loaded [Cert](#cert-property-certmgr-component).

The component will first obtain the OCSP URL from the certificate's OCSP extension. The component will then locate the issuing certificate and make an HTTP request to the OCSP endpoint to check the validity of the certificate.

If the certificate has been revoked or any other issues are found during validation, the component throws an exception. To check whether the certificate supports the OCSP extension, use the [HasOCSP](#HasOCSP) configuration setting.

# Config Method ([CertMgr](#certmgr-component) Component)

Sets or retrieves a configuration setting.

## Syntax

```text
public string Config(string configurationString);

Async Version
public async Task<string> Config(string configurationString);
public async Task<string> Config(string configurationString, CancellationToken cancellationToken);
```

## Remarks

Config is a generic method available in every component. It is used to set and retrieve [configuration settings](#config-settings-certmgr-component) for the component.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these *internal properties* is provided through the Config method.

To set a configuration setting named *PROPERTY*, you must call *Config("PROPERTY=VALUE")*, where *VALUE* is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a [configuration setting](#config-settings-certmgr-component), you must call *Config("PROPERTY")*. The value will be returned as a string.

# CreateCertificate Method ([CertMgr](#certmgr-component) Component)

This method creates a new self-signed certificate in the current store.

## Syntax

```text
public void CreateCertificate(string certSubject, int serialNumber);

Async Version
public async Task CreateCertificate(string certSubject, int serialNumber);
public async Task CreateCertificate(string certSubject, int serialNumber, CancellationToken cancellationToken);
```

## Remarks

This method creates a new self-signed certificate in the current store, which contains the following:

*CertSubject* specifies the subject of the new certificate. A new keyset (public/private key pair) is generated and associated with the new certificate.

The certificate subject is a comma-separated list of distinguished name fields and values. For instance, "CN=www.server.com, OU=test, C=US, E=example@email.com". Common fields and their meanings are as follows:

| Field | Meaning |
| --- | --- |
| CN | Common Name. This is commonly a hostname like www.server.com. |
| O | Organization |
| OU | Organizational Unit |
| L | Locality |
| S | State |
| C | Country |
| E | Email Address |

If a field value contains a comma, it must be quoted.

*SerialNumber* specifies the certificate serial number. All certificates signed by the same issuer must have different (unique) serial numbers.

The time validity of the new certificate is determined by the [CertValidityTime](#CertValidityTime) configuration setting, and the key size by the [CertKeyLength](#CertKeyLength) configuration setting.

# CreateKey Method ([CertMgr](#certmgr-component) Component)

This method creates a new keyset associated with the provided name.

## Syntax

```text
public void CreateKey(string keyName);

Async Version
public async Task CreateKey(string keyName);
public async Task CreateKey(string keyName, CancellationToken cancellationToken);
```

## Remarks

This method will create a new keyset (public/private key pair) within the Cryptographic Service Provider (CSP) used by the component. The CSP can be set using the [CSP](#CSP) configuration setting.

NOTE: This functionality is only available in Windows.

# DeleteCertificate Method ([CertMgr](#certmgr-component) Component)

This method deletes the currently selected certificate from the store.

## Syntax

```text
public void DeleteCertificate();

Async Version
public async Task DeleteCertificate();
public async Task DeleteCertificate(CancellationToken cancellationToken);
```

## Remarks

This method will delete the selected certificate from the store. If the certificate cannot be deleted, an error is returned.

 This functionality is currently not available when the provider is OpenSSL.

# DeleteKey Method ([CertMgr](#certmgr-component) Component)

This method deletes the keyset associated with the provided name.

## Syntax

```text
public void DeleteKey(string keyName);

Async Version
public async Task DeleteKey(string keyName);
public async Task DeleteKey(string keyName, CancellationToken cancellationToken);
```

## Remarks

This method will delete the keyset (public/private key pair) associated with *KeyName* from the Cryptographic Service Provider (CSP). The CSP can be set using the [CSP](#CSP) configuration setting.

NOTE: This functionality is only available in Windows.

# ExportCertificate Method ([CertMgr](#certmgr-component) Component)

This method exports the currently selected certificate.

## Syntax

```text
public void ExportCertificate(string certFile, string password);

Async Version
public async Task ExportCertificate(string certFile, string password);
public async Task ExportCertificate(string certFile, string password, CancellationToken cancellationToken);
```

## Remarks

This method exports the certificate currently selected by [Cert](#cert-property-certmgr-component) to the file specified by the *CertFile* parameter in the format specified by [ExportFormat](#exportformat-property-certmgr-component). This method may be used effectively to convert between a variety of formats.

The *Password* parameter specifies a password for the private key when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is set to *True*. *Password* is not applicable when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is set to *False*.

If *CertFile* is set to an empty string, the exported certificate will not be written to disk and instead will be held as a string by the [ExportedCert](#exportedcert-property-certmgr-component) property.

[ExportFormat](#exportformat-property-certmgr-component) is applicable when ExportCertificate is called and may be used to specify the output format. The applicability of each format depends on whether [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is set. Some formats are applicable only when exporting to a private key and some values are applicable only when exporting to a public key.

```text
-----BEGIN CERTIFICATE-----
MIIBkTCB+6ADAgECAgEBMA0GCSqGSIb3DQEBBQUAMA4xDDAKBgNVBAMTAzEwMDAgFw0wNzAx
...
Pg49SpQ+HcUibIpum2O0hmnySH7BPGfXD8Lu
-----END CERTIFICATE-----
```

```text
-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQD5/STHUd7YkN1JyoyYnUvCf+Fyx1+ZleBJxvwDcm3yaZ98bvry
...
91y8ydb3mQ9l1hZudo2sj8tHnvEgph0r7B8hMM6Qaw==
-----END RSA PRIVATE KEY-----
```

```text
-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBALAyxV5assz+9v7aHbj93NYN5uGB/1z7kb2Nx4hj02QyRYbcD4htkhK4Qcq2GCsG
...
MxW4+pdeN4oEZ6rbMZt01bvMwNRX2GDEyQBhAgMBAAE=
-----END RSA PUBLIC KEY-----
```

```text
-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQD5/STHUd7YkN1JyoyYnUvCf+Fyx1+ZleBJxvwDcm3yaZ98bvry
...
91y8ydb3mQ9l1hZudo2sj8tHnvEgph0r7B8hMM6Qaw==
-----END RSA PRIVATE KEY-----
```

```text
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxdTNtpJQbw90cq6aJEx5vRIBrAiCAB9/F
...
8UdUliXeU8UGYjVcMhGy5oPsVeBXGcPAqF2mjXdBKNnzlSlctOLnYRBS5jwRuNfTQQIDAQAB
-----END PUBLIC KEY-----
```

```text
-----BEGIN PRIVATE KEY-----
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAPn9JMdR3tiQ3UnK
...
HSvsHyEwzpBr
-----END PRIVATE KEY-----
```

```text
ssh-rsa AAAAB3NzaC1y...
```

```text
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAlwAAAAdzc2gtcnNh
...
AwQFBgcICQo=
-----END OPENSSH PRIVATE KEY-----
```

```text
PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: rsa-key-20180822
Public-Lines: 4
AAAAB3NzaC1yc2EAAAADAQABAAAAgQCmz5j5kWUKxfwiv6J0LQ4wN9ekpeORXVaP
...
8pSSWejQ5Q==
Private-Lines: 8
AAAAgH87Sp/YcSw1dKoAZuWb0/2dKkKwMRIYEkS15caRpzAteay6WWX7l1sgBTU7
...
Oa0=
Private-MAC: d53e24f44bde8d1d3844a142fbb1fa7c88ea3585
```

```text
---- BEGIN SSH2 PUBLIC KEY ----
AAAAB3NzaC1yc2EAAAADAQABAAAAgQD5/STHUd7YkN1JyoyYnUvCf+Fyx1+ZleBJxvwDcm3y
...
6bVPTODELil1PVWJDlfdwoLZZKY2ACFHzxBqaOlYv1rbd2JIYAuqGca2ow==
---- END SSH2 PUBLIC KEY ----
```

```text
---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----
AAAAB3NzaC1yc2EAAAADAQABAAAAgQD5/STHUd7YkN1JyoyYnUvCf+Fyx1+ZleBJxvwDcm3y
...
6bVPTODELil1PVWJDlfdwoLZZKY2ACFHzxBqaOlYv1rbd2JIYAuqGca2ow==
---- END SSH2 ENCRYPTED PRIVATE KEY ----
```

```text
{
	"kty": "EC",
	"crv": "P-256",
	"x": "M_P_uqzP43FYW-kXWlpEDlX3nPZUr1QaMllAxUnao7w",
	"y": "zRFhp7iCXYIoTgerQ4LjGPTujodlimrwIMk-3enj_1Q"
}
```

```text
{
	"kty": "EC",
	"crv": "P-256",
	"x": "M_P_uqzP43FYW-kXWlpEDlX3nPZUr1QaMllAxUnao7w",
	"y": "zRFhp7iCXYIoTgerQ4LjGPTujodlimrwIMk-3enj_1Q",
	"d": "eFBtl-uaB9Y4b-CIav5IYX4gGRFBvpBmrMOOQ7L-euI"
}
```

```text
<X509Data>
	<X509Certificate>MIIB...D8Lu</X509Certificate>
</X509Data>
```

```text
<RSAKeyValue>
	<Modulus>+f0k...tqM=</Modulus>
	<Exponent>AQAB</Exponent>
	<P>/cOnF...tGw==</P>
	<Q>/DD5...dGQ==</Q>
	<DP>d75...N0w==</DP>
	<DQ>Cyv...rKQ==</DQ>
	<InverseQ>fsB...Qaw==</InverseQ>
	<D>J7p...YJE=</D>
</RSAKeyValue>
```

| ExportFormat | Applicability | Description |
| --- | --- | --- |
| "PFX" or "PKCS12" (default) | Private Keys | A PFX file (PKCS12). |
| "PEM" | Public and Private Keys | A PEM-formatted public certificate (X509/PKCS1/PKCS8), or PEM formatted private key (PKCS1/PKCS8). When [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False the exported certificate will be a PEM formatted X509 public certificate if the certificate being exported includes X509 data. If no X509 information is present, the public key will be exported in PKCS1 public key format for RSA/DSA keys and PKCS8 public key format for ECDSA/EdDSA keys. When [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True the exported certificate will be a PEM-formatted PKCS1 private key for RSA/DSA keys and a PEM-formatted PKCS8 private key for ECDSA/EdDSA keys. For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: Example when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |
| "PKCS1" | Public and Private Keys | A PEM-formatted PKCS1 key file. For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: Example when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |
| "PKCS8" | Public and Private Keys | A PEM-formatted PKCS8 key file. Example when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: Example when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |
| "OpenSSH" | Public and Private Keys | An OpenSSH public or private key file. For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: Example when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |
| "PPK" | Private Keys | A PuTTY private key file. For example, |
| "SSH2PublicKey" | Public Keys | An SSH2 public key. For example, |
| "SSH2PrivateKey" | Private Keys | An SSH2 private key. For example, |
| "JWK" | Private and Public Keys | A JSON Web Key (JWK). For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |
| "XML" | Private and Public Keys | An XML file holding the key or X509 data. For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is False: For example, when [ExportPrivateKey](#exportprivatekey-property-certmgr-component) is True: |

**ExportCertificate Example:**

```csharp
//Convert from PFX to PPK
certmgr.Cert = new Certificate(CertStoreTypes.cstPFXFile, "..\\test.pfx", "password", "*");
certmgr.ExportPrivateKey = true;
certmgr.ExportFormat = "PPK";
certmgr.ExportCertificate("..\\test.ppk", "newpassword");

//Export public certificate from PFX
certmgr.Cert = new Certificate(CertStoreTypes.cstPFXFile, "..\\test.pfx", "password", "*");
certmgr.ExportPrivateKey = false;
certmgr.ExportFormat = "PEM";
certmgr.ExportCertificate("..\\exported.cer", "");

//Convert .cer file to SSH2 Public Key
certmgr.Cert = new Certificate("..\\exported.cer");
certmgr.ExportPrivateKey = false;
certmgr.ExportFormat = "SSH2PublicKey";
certmgr.ExportCertificate("..\\ssh2.pub", "");
```

# GenerateCSR Method ([CertMgr](#certmgr-component) Component)

This method generates a new Certificate Signing Request (CSR) to be sent to a signing authority.

## Syntax

```text
public string GenerateCSR(string certSubject, string keyName);

Async Version
public async Task<string> GenerateCSR(string certSubject, string keyName);
public async Task<string> GenerateCSR(string certSubject, string keyName, CancellationToken cancellationToken);
```

## Remarks

This method will generate a new CSR to be sent to the signing authority. *CertSubject* specifies the subject of the CSR. *KeyName* specifies the name of the keyset (public/private key pair) to be used. If the keyset does not already exist in the Cryptographic Service Provider (CSP), the component will automatically generate one. To set the CSP, use the [CSP](#CSP) configuration setting.

NOTE: Remember the name of the keyset that is used when creating a CSR. The keyset must be re-associated with the certificate after the trust authority has signed the CSR.

The certificate subject is a comma-separated list of distinguished name fields and values. For instance, "CN=www.server.com, OU=test, C=US, E=example@email.com". Common fields and their meanings are as follows:

| Field | Meaning |
| --- | --- |
| CN | Common Name. This is commonly a hostname like www.server.com. |
| O | Organization |
| OU | Organizational Unit |
| L | Locality |
| S | State |
| C | Country |
| E | Email Address |

If a field value contains a comma, it must be quoted.

NOTE: This functionality is only available in Windows.

# ImportCertificate Method ([CertMgr](#certmgr-component) Component)

This method imports a certificate from a file into the current certificate store.

## Syntax

```text
public void ImportCertificate(string certFile, string password, string subject);

Async Version
public async Task ImportCertificate(string certFile, string password, string subject);
public async Task ImportCertificate(string certFile, string password, string subject, CancellationToken cancellationToken);
```

## Remarks

This method will import a certificate from a file into the current certificate store.

On Windows platforms, certificates may be imported only to the Windows certificate store. To load a certificate without importing it to a Windows store, set [Cert](#cert-property-certmgr-component).

Certificate files with or without a private key may be imported. If the file specified by *CertFile* contains a private key, the private key will be imported along with the public certificate. If the file specified by *CertFile* contains only a public certificate, only the public certificate will be imported.

The *Password* parameter specifies the certificate password (if any). When importing a public certificate, set *Password* to an empty string.

The format of the certificate file being imported must contain valid X509 data to be imported. Not all certificate file formats include X509 data, such as PPK or PKCS8 private keys. If the *CertFile* is of a format that cannot be imported, the component throws an exception.

*Subject* is optional. If empty, the first certificate in the store is loaded instead of the matching certificate.

**ImportCertificate Example**

```csharp
//Import a PFX
certmgr.ImportCertificate("..\\test.pfx", "password", "*");

//Import a public certificate (CER)
certmgr.ImportCertificate("..\\test.cer", "", "*");
```

# ImportSignedCSR Method ([CertMgr](#certmgr-component) Component)

This method imports a signed Certificate Signing Request (CSR).

## Syntax

```text
public void ImportSignedCSR(byte[] signedCSR, string keyName);

Async Version
public async Task ImportSignedCSR(byte[] signedCSR, string keyName);
public async Task ImportSignedCSR(byte[] signedCSR, string keyName, CancellationToken cancellationToken);
```

## Remarks

This method will import a signed CSR. *SignedCSR* specifies a certificate that has been signed by a trusted authority. *KeyName* is the name of the keyset (public/private key pair) that was used to create the original CSR.

NOTE: This functionality is only available in Windows.

# IssueCertificate Method ([CertMgr](#certmgr-component) Component)

This creates a new certificate in the current store and is signed by the selected certificate.

## Syntax

```text
public void IssueCertificate(string certSubject, int serialNumber);

Async Version
public async Task IssueCertificate(string certSubject, int serialNumber);
public async Task IssueCertificate(string certSubject, int serialNumber, CancellationToken cancellationToken);
```

## Remarks

This method creates a new certificate in the current store and is signed by the selected certificate. *CertSubject* specifies the subject of the new certificate. A new keyset (public/private key pair) is generated and associated with the new certificate.

The certificate subject is a comma-separated list of distinguished name fields and values. For instance, "CN=www.server.com, OU=test, C=US, E=example@email.com". Common fields and their meanings are as follows:

| Field | Meaning |
| --- | --- |
| CN | Common Name. This is commonly a hostname like www.server.com. |
| O | Organization |
| OU | Organizational Unit |
| L | Locality |
| S | State |
| C | Country |
| E | Email Address |

If a field value contains a comma, it must be quoted.

*SerialNumber* specifies the certificate serial number. All certificates signed by the same issuer must have different (unique) serial numbers.

The current certificate selected by the component will be used as the issuing certificate.

If no certificate has been selected in the current [CertStore](#certstore-property-certmgr-component) before calling this method, or if the selected certificate does not have an associated private key, the method throws an exception.

The time validity of the new certificate is determined by the [CertValidityTime](#CertValidityTime) configuration setting, and the key size by the [CertKeyLength](#CertKeyLength) configuration setting.

NOTE: This functionality is only available in Windows.

# ListCertificateStores Method ([CertMgr](#certmgr-component) Component)

This lists the certificate stores.

## Syntax

```text
public string ListCertificateStores();

Async Version
public async Task<string> ListCertificateStores();
public async Task<string> ListCertificateStores(CancellationToken cancellationToken);
```

## Remarks

This method lists the system certificate stores for the current user account. The results are provided through the [StoreList](#storelist-event-certmgr-component) event.

The same information is also returned upon method completion as a set of lines and is given one per certificate store name.

NOTE: This functionality is only available in Windows.

# ListKeys Method ([CertMgr](#certmgr-component) Component)

This lists the keysets in a Cryptographic Service Provider (CSP).

## Syntax

```text
public string ListKeys();

Async Version
public async Task<string> ListKeys();
public async Task<string> ListKeys(CancellationToken cancellationToken);
```

## Remarks

This method lists the keys (public/private key pairs) in a CSP. The results are provided through the [KeyList](#keylist-event-certmgr-component) event.

The same information is also returned upon method completion as a set of lines and is given one per key, with each line containing the following information separated by Tab characters: *KeyContainer*, *KeyType*, *AlgId*, and *KeyLen*.

NOTE: This functionality is only available in Windows.

# ListMachineStores Method ([CertMgr](#certmgr-component) Component)

This lists the machine certificate stores.

## Syntax

```text
public string ListMachineStores();

Async Version
public async Task<string> ListMachineStores();
public async Task<string> ListMachineStores(CancellationToken cancellationToken);
```

## Remarks

This method behaves the same as the [ListCertificateStores](#listcertificatestores-method-certmgr-component) method, but it lists the certificate stores in the machine account (under HKEY_LOCAL_MACHINE in the registry).

NOTE: This functionality is only available in Windows.

# ListStoreCertificates Method ([CertMgr](#certmgr-component) Component)

This lists the certificates in a store.

## Syntax

```text
public string ListStoreCertificates();

Async Version
public async Task<string> ListStoreCertificates();
public async Task<string> ListStoreCertificates(CancellationToken cancellationToken);
```

## Remarks

This method lists the certificates in a store. The results are provided through the [CertList](#certlist-event-certmgr-component) event.

The same information is also returned upon method completion as a set of lines and is given one per certificate, with each line containing the following information separated by Tab characters: *CertSubject*, *CertIssuer*, *CertSerialNumber*, and *HasPrivateKey* (as "1" or "0").

# ReadCertificate Method ([CertMgr](#certmgr-component) Component)

This loads a certificate from a file.

## Syntax

```text
public void ReadCertificate(string fileName);

Async Version
public async Task ReadCertificate(string fileName);
public async Task ReadCertificate(string fileName, CancellationToken cancellationToken);
```

## Remarks

NOTE: This method is present for backward compatibility. It is recommended to specify the [Cert](#cert-property-certmgr-component) property to load a certificate.

This method will load a certificate from a file. The file contents can be encoded in Base64 PEM or ASN DER format.

# ReadCSR Method ([CertMgr](#certmgr-component) Component)

This reads a Certificate Signing Request (CSR).

## Syntax

```text
public string ReadCSR(string CSR);

Async Version
public async Task<string> ReadCSR(string CSR);
public async Task<string> ReadCSR(string CSR, CancellationToken cancellationToken);
```

## Remarks

This method reads a CSR and returns a string holding information about the CSR. The [Cert](#cert-property-certmgr-component) property is also populated with relevant information about the CSR, including the following:

- [Subject](#Certificate_f_Subject)
- [PublicKeyLength](#Certificate_f_PublicKeyLength)
- [PublicKeyAlgorithm](#Certificate_f_PublicKeyAlgorithm)

 The method accepts the *CSR* parameter as either a Base64-encoded string PEM or a path to a file.

The return value will be in the following format:

```text
Certificate Request:
    Data:
        Version: 0 (0x0)
        Subject: C=AU, S=Some-State, O=Internet Widgits Pty Ltd
        Subject Public Key Info:
            Public Key Algorithm: X957_DSA (1.2.840.10040.4.1)
                Public-Key: (0 bit)
                pub:
                    02:82:01:00:66:70:68:60:08:63:bc:ff:26:62:77:74:
                    f6:b8:a8:11:f4:2c:5d:a1:79:b9:8e:ea:30:2e:6b:5a:
                    1b:35:39:24:91:1b:c1:ba:49:a0:c5:af:47:6e:73:0a:
                    f3:f6:6b:99:94:21:32:e5:24:b3:a8:a4:85:93:84:26:
                    e8:5c:4a:5d:2e:5e:82:df:ab:cc:e5:8d:51:ac:45:c2:
                    09:e5:21:f1:ce:c9:a0:3d:1d:7a:ab:fa:dd:d6:56:a8:
                    b2:61:26:8e:27:83:36:8a:0c:9b:cb:61:1a:b5:63:95:
                    ef:a5:bd:f2:8e:a7:fc:ca:d2:81:87:a5:6a:88:03:2e:
                    ca:fb:24:fa:d0:df:8a:2e:a9:e0:31:fc:57:e1:02:ca:
                    ee:99:01:d2:a5:33:34:47:92:b3:8b:31:f5:f1:1d:bf:
                    eb:07:70:71:6f:d1:c0:4c:0a:9d:99:af:ae:7e:bc:85:
                    e4:d2:22:1c:38:4b:60:e8:31:4d:f7:10:06:10:03:55:
                    f5:af:ba:a9:53:a5:9b:ae:d1:f8:38:34:80:e4:1c:9e:
                    06:8d:cc:39:3e:b2:e9:32:82:85:d2:d0:ed:b2:8e:d6:
                    6f:96:87:08:62:cc:9e:d3:75:76:b5:85:31:c6:a4:94:
                    59:15:ec:de:70:5a:34:2c:ff:27:ad:fc:14:01:e6:39:
                    8a:c9:91:3e:
                P:
                    00:dc:a6:15:cc:1a:e1:44:16:dc:a8:68:a4:18:9a:ab:
                    bf:5d:bf:b7:d1:5e:38:5f:b6:0e:21:ef:df:83:6a:5c:
                    31:f0:c9:07:3c:13:2c:9c:32:d0:89:76:2b:80:ad:3f:
                    6b:5d:5a:1d:69:31:f5:80:d5:65:ba:b5:28:a3:38:ba:
                    93:25:c4:fc:93:99:a2:00:5d:5e:c6:1b:f2:63:f0:24:
                    72:52:b4:49:97:19:93:fe:47:bf:9e:2e:54:d1:8a:b9:
                    09:8d:54:e8:de:31:e8:0d:21:b0:81:b2:f5:bd:38:3c:
                    15:02:d6:c1:aa:ab:17:8f:a8:f8:1f:1b:34:09:85:75:
                    3d:6e:28:2d:72:af:47:fd:ae:c4:f3:78:53:d7:07:a7:
                    c4:72:35:2d:6b:9e:42:08:1d:46:c9:38:d2:53:27:63:
                    a2:1d:be:11:9f:dd:9d:5b:e4:ad:fa:71:30:61:84:60:
                    a0:bf:bd:3a:51:b4:b5:1e:48:26:36:66:9e:52:f9:70:
                    35:e3:38:53:2e:90:ed:9f:0f:9d:67:b9:57:dd:53:e6:
                    ca:92:58:40:6d:15:e4:ae:2e:16:74:33:ed:48:90:15:
                    30:b7:fd:47:58:91:d5:c5:e2:3b:1f:1d:3b:a7:59:40:
                    2e:22:1a:9a:89:1b:31:a2:6f:cf:4c:a1:3b:93:ed:8a:
                    11:
                Q:
                    00:e3:ae:12:04:80:be:0f:d4:78:ef:02:27:26:b3:64:
                    6d:2b:e0:c9:da:15:00:a9:9c:45:6d:e6:44:ef:dd:75:
                    71:
                G:
                    18:fb:52:54:fe:bc:54:9e:17:a9:51:a1:e0:b9:6a:ab:
                    48:0e:06:60:f3:cd:fd:3c:14:9a:a0:35:d1:33:d4:d8:
                    b4:ee:ce:0b:5c:c7:60:24:e8:39:17:d8:75:13:90:44:
                    f5:f6:ef:50:cd:b4:af:66:90:f7:00:13:66:2f:ea:e2:
                    29:39:cd:a4:16:20:df:00:fd:53:6d:02:8b:4f:09:a5:
                    7f:72:7c:28:c8:70:2a:85:49:a1:65:36:66:91:52:e7:
                    14:b1:b8:b9:79:39:a6:d5:f8:b9:cd:ce:af:2d:88:66:
                    b5:d9:bb:9e:60:c8:9e:82:b4:3f:ff:23:37:4b:20:e4:
                    88:b0:d4:6e:b7:b5:8c:e6:98:cb:88:c2:6e:10:46:af:
                    44:0f:53:22:c2:fb:80:d3:30:05:c0:a6:4b:f8:e0:08:
                    3e:69:b6:17:b1:7d:2f:8f:07:66:9c:e5:94:3f:fc:ea:
                    f9:6c:9d:49:7c:91:f3:5a:92:b4:a7:b9:dc:42:7d:1a:
                    b0:99:ad:6d:b8:d9:03:6e:40:13:1c:3e:e2:80:f5:a1:
                    da:75:49:29:be:36:ad:78:74:46:0d:00:e9:6d:bf:8c:
                    65:50:4c:ad:ba:a7:1c:ac:5a:13:9e:d6:6a:3a:9f:cb:
                    1f:7d:5d:e2:3e:79:22:c2:56:c8:70:74:53:9a:4e:6c:
        Attributes:

    Signature Algorithm: 2.16.840.1.101.3.4.3.2 (2.16.840.1.101.3.4.3.2)
        00:30:44:02:20:42:00:86:14:2d:70:71:1b:77:b4:f0:
        ae:32:76:7b:1d:71:98:a2:70:69:4c:a9:e6:c1:9b:ad:
        df:af:a3:30:10:02:20:12:8f:ed:0b:1e:d5:f6:84:24:
        a9:fe:bc:45:75:eb:02:62:13:07:2c:ae:3f:ce:f3:da:
        95:25:47:97:bf:a6:9e:
```

# Reset Method ([CertMgr](#certmgr-component) Component)

This resets all certificate properties to their default values.

## Syntax

```text
public void Reset();

Async Version
public async Task Reset();
public async Task Reset(CancellationToken cancellationToken);
```

## Remarks

This method will reset all certificate properties to their default values. If a certificate and a private key are selected or a certificate store is opened, both are released upon calling this method.

# SaveCertificate Method ([CertMgr](#certmgr-component) Component)

This method saves the currently selected public certificate to a file.

## Syntax

```text
public void SaveCertificate(string fileName);

Async Version
public async Task SaveCertificate(string fileName);
public async Task SaveCertificate(string fileName, CancellationToken cancellationToken);
```

## Remarks

NOTE: This method is present for backward compatibility. It is recommended to use [ExportCertificate](#exportcertificate-method-certmgr-component) to export both public and private certificates and keys.

This method saves the public certificate of the currently selected certificate in Base64 PEM format to the location specified by the *FileName* parameter.

If the destination file exists, it is overwritten.

# ShowCertificateChain Method ([CertMgr](#certmgr-component) Component)

This shows the certificate chain.

## Syntax

```text
public string ShowCertificateChain();

Async Version
public async Task<string> ShowCertificateChain();
public async Task<string> ShowCertificateChain(CancellationToken cancellationToken);
```

## Remarks

This method shows the certificate chain for the certificate. The results are provided through the [CertChain](#certchain-event-certmgr-component) event.

The same information is also returned upon method completion as a set of lines and is given one per key, with each line containing the following information separated by Tab characters: *CertSubject*, *CertIssuer*, *CertSerialNumber*, *TrustStatus*, and *TrustInfo*.

NOTE: This functionality is only available in Windows.

# SignCSR Method ([CertMgr](#certmgr-component) Component)

This creates a signed certificate from a Certificate Signing Request (CSR).

## Syntax

```text
public string SignCSR(byte[] CSR, int serialNumber);

Async Version
public async Task<string> SignCSR(byte[] CSR, int serialNumber);
public async Task<string> SignCSR(byte[] CSR, int serialNumber, CancellationToken cancellationToken);
```

## Remarks

This method will create a signed certificate from a CSR. *CSR* specifies the CSR to be signed.

*SerialNumber* specifies the certificate serial number. All certificates signed by the same issuer must have different (unique) serial numbers.

The time validity of the new certificate is determined by the [CertValidityTime](#CertValidityTime) configuration setting, and the key size is determined by the [CertKeyLength](#CertKeyLength) configuration setting.

NOTE: This functionality is only available in Windows.

# CertChain Event ([CertMgr](#certmgr-component) Component)

This event shows the certificate chain for the certificate (see the [ShowCertificateChain](#showcertificatechain-method-certmgr-component) method).

## Syntax

```text
public event OnCertChainHandler OnCertChain;

public delegate void OnCertChainHandler(object sender, CertMgrCertChainEventArgs e);

public class CertMgrCertChainEventArgs : EventArgs {
  public string CertEncoded { get; }  public byte[] CertEncodedB { get; }
  public string CertSubject { get; }
  public string CertIssuer { get; }
  public string CertSerialNumber { get; }
  public int TrustStatus { get; }
  public int TrustInfo { get; }
}
```

## Remarks

This event is fired for every certificate in the certificate chain of the certificate assigned to the component.

The *TrustStatus* parameter contains information about the trust status of the entire certificate chain. A value of 0 signifies that the security subsystem has verified the certificate. Other values are combinations of one or more of the following flags:

|  |  |
| --- | --- |
| 0x00000001 | This certificate or one of the certificates in the certificate chain is not time valid. |
| 0x00000002 | Certificates in the chain are not properly time nested. |
| 0x00000004 | Trust for this certificate or one of the certificates in the certificate chain has been revoked. |
| 0x00000008 | This certificate or one of the certificates in the certificate chain does not have a valid signature. |
| 0x00000010 | The certificate or the certificate chain is not valid for its proposed usage. |
| 0x00000020 | The certificate or certificate chain is based on an untrusted root. |
| 0x00000040 | The revocation status of the certificate or one of the certificates in the certificate chain is unknown. |
| 0x00000080 | One of the certificates in the chain was issued by a certification authority that the original certificate had certified. |
| 0x00010000 | The certificate chain is not complete. |
| 0x00020000 | A certificate trust list (CTL) used to create this chain was not time valid. |
| 0x00040000 | A CTL used to create this chain did not have a valid signature. |
| 0x00080000 | A CTL used to create this chain is not valid for this usage. |

The *TrustInfo* parameter contains additional information about the status of the entire certificate chain. It is a combination of one or more of the following flags:

|  |  |
| --- | --- |
| 0x00000001 | An exact match issuer certificate has been found for this certificate. |
| 0x00000002 | A key match issuer certificate has been found for this certificate. |
| 0x00000004 | A name match issuer certificate has been found for this certificate. |
| 0x00000008 | This certificate is self-signed. |
| 0x00010000 | The certificate chain created is a complex chain. |

The *CertSubject* and *CertIssuer* parameters contain the distinguished names of the certificate owner and issuer, respectively.

# CertList Event ([CertMgr](#certmgr-component) Component)

This event lists the certificates in a store (see the [ListStoreCertificates](#liststorecertificates-method-certmgr-component) method).

## Syntax

```text
public event OnCertListHandler OnCertList;

public delegate void OnCertListHandler(object sender, CertMgrCertListEventArgs e);

public class CertMgrCertListEventArgs : EventArgs {
  public string CertEncoded { get; }  public byte[] CertEncodedB { get; }
  public string CertSubject { get; }
  public string CertIssuer { get; }
  public string CertSerialNumber { get; }
  public bool HasPrivateKey { get; }
}
```

## Remarks

The *CertSubject* and *CertIssuer* parameters contain distinguished names of the certificate owner and issuer, respectively. The *HasPrivateKey* flag shows whether the private key for the certificate is available in the system.

The [StoreList](#storelist-event-certmgr-component) event and the [ListCertificateStores](#listcertificatestores-method-certmgr-component) and [ListMachineStores](#listmachinestores-method-certmgr-component) methods are used to list the certificate stores in the system.

# Error Event ([CertMgr](#certmgr-component) Component)

Fired when information is available about errors during data delivery.

## Syntax

```text
public event OnErrorHandler OnError;

public delegate void OnErrorHandler(object sender, CertMgrErrorEventArgs e);

public class CertMgrErrorEventArgs : EventArgs {
  public int ErrorCode { get; }
  public string Description { get; }
}
```

## Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally the component throws an exception.

The *ErrorCode* parameter contains an error code, and the *Description* parameter contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the [Error Codes](#trappable-errors-certmgr-component) section.

# KeyList Event ([CertMgr](#certmgr-component) Component)

This lists the keysets in a Cryptographic Service Provider (CSP); see the [ListKeys](#listkeys-method-certmgr-component) method.

## Syntax

```text
public event OnKeyListHandler OnKeyList;

public delegate void OnKeyListHandler(object sender, CertMgrKeyListEventArgs e);

public class CertMgrKeyListEventArgs : EventArgs {
  public string KeyContainer { get; }
  public int KeyType { get; }
  public string AlgId { get; }
  public int KeyLen { get; }
}
```

## Remarks

The *KeyContainer* parameter is the name used to identify the keyset (public/private key pair) when it was first created.

*KeyType* shows the key type: 1 for key exchange (encryption) keys, and 2 for digital signature keys.

*KeyLen* shows the length of the public key (in bits).

# Log Event ([CertMgr](#certmgr-component) Component)

This event fires once for each log message.

## Syntax

```text
public event OnLogHandler OnLog;

public delegate void OnLogHandler(object sender, CertMgrLogEventArgs e);

public class CertMgrLogEventArgs : EventArgs {
  public int LogLevel { get; }
  public string Message { get; }
  public string LogType { get; }
}
```

## Remarks

This event fires once for each log message generated by the component. The verbosity is controlled by the [LogLevel](#LogLevel) setting.

*LogLevel* indicates the level of message. Possible values are as follows:

|  |  |
| --- | --- |
| 0 (None) | No events are logged. |
| 1 (Info - default) | Informational events are logged. |
| 2 (Verbose) | Detailed data are logged. |
| 3 (Debug) | Debug data are logged. |

*Message* is the log entry.

*LogType* identifies the type of log entry.

# StoreList Event ([CertMgr](#certmgr-component) Component)

This lists the system certificate stores (see the [ListCertificateStores](#listcertificatestores-method-certmgr-component) and [ListMachineStores](#listmachinestores-method-certmgr-component) methods).

## Syntax

```text
public event OnStoreListHandler OnStoreList;

public delegate void OnStoreListHandler(object sender, CertMgrStoreListEventArgs e);

public class CertMgrStoreListEventArgs : EventArgs {
  public string CertStore { get; }
}
```

## Remarks

The *CertStore* parameter contains the name of the certificate store being listed.

The [CertList](#certlist-event-certmgr-component) event and the [ListStoreCertificates](#liststorecertificates-method-certmgr-component) method are used to list the certificates in the store.

# CertExtension Type

This represents an extension for a certificate.

## Remarks

A [CertExtension](#certextension-type) represents an extension that adds to or modifies an X509 [Certificate](#certificate-type). Certificate extensions are defined by their ASN.1 Object-Identifier ([OID](#CertExtension_f_OID)). The [Value](#CertExtension_f_Value) field contains the raw data of the extension, which is usually ASN.1 encoded.

The following fields are available:

- [Critical](#CertExtension_f_Critical)

- [OID](#CertExtension_f_OID)

- [Value](#CertExtension_f_Value)

## Fields

 **Critical** *bool (read-only)*
Default: False

This field specifies whether or not the extension is defined as critical.

 **OID** *string (read-only)*
Default: ""

This field contains the ASN.1 Object-Identifier (**OID**) that defines this certificate extension.

 **Value** *string (read-only)*
Default: ""

This field contains the raw value of the certificate extension. This value is encoded according to the extension's ASN.1 specification and should contain everything following the OID. The following example is provided for clarity.

 The example will

- Add a sequence of *basicConstraints* indicating the holder of this certificate may not act as a CA.
- Add a sequence of *cRLDistributionPoints* showing where to get CRLs.

```csharp
Certmgr mgr = new Certmgr();
mgr.Cert = new Certificate(CertStoreTypes.cstPFXFile, @"C:\signingcert.pfx", "password", "*");
mgr.CertExtensions.Clear();
mgr.Config("CertUsageFlags=0xA0"); //Key Encipherment and Digital Signature
mgr.Config("CertExtendedKeyUsage=1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2"); //Server and Client authentication (respectively)
mgr.Config("CertValidityTime=10000");

Netcode nc = new Netcode();
nc.Format = NetcodeFormats.fmtHex;

// Set basicConstraints to be an end-entity.
// Below is the hex-encoded value broken down.
// 30     // Tag = sequence
// 03     // Length
//   01   // Tag = boolean
//   01   // Length
//     00 // False (not a CA)

// Convert hex string to byte[]
nc.EncodedData = "3003010100";
nc.Decode();

string oid = "2.5.29.19"; // basicConstraints
byte[] value = nc.DecodedDataB;
bool critical = false;
CertExtension basicConstraints = new CertExtension(oid, value, critical);
mgr.CertExtensions.Add(basicConstraints);

// Add one point: http://www.nsoftware.com/dummy/MyCA.crl
// Below is the hex-encoded value broken down.
// 30                    // Tag = sequence
// 2F                    // Length
//   30                  // Tag = DistributionPoint
//   2D                  // Length
//     A0                // Tag = DistributionPointName
//     2B                // Length
//       A0              // Tag = GeneralNames
//       29              // Length
//         86            // Tag = GeneralName
//         27            // Length
//           687474703A2F2F7777772E6E736F6674776172652E636F6D2F64756D6D792F4D7943412E63726C // URL

// Convert hex string to byte[]
nc.EncodedData = "302F302DA02BA0298627687474703A2F2F7777772E6E736F6674776172652E636F6D2F64756D6D792F4D7943412E63726C";
nc.Decode();

oid = "2.5.29.31"; // cRLDistributionPoints
value = nc.DecodedDataB;
critical = false;
CertExtension crlDistributionPoints = new CertExtension(oid, value, critical);
mgr.CertExtensions.Add(crlDistributionPoints);

mgr.IssueCertificate("CN=www.petsbymatilda.com", 123);
Console.WriteLine(mgr.Cert.Encoded);
```

 **ValueB** *byte [] (read-only)*
Default: ""

This field contains the raw value of the certificate extension. This value is encoded according to the extension's ASN.1 specification and should contain everything following the OID. The following example is provided for clarity.

 The example will

- Add a sequence of *basicConstraints* indicating the holder of this certificate may not act as a CA.
- Add a sequence of *cRLDistributionPoints* showing where to get CRLs.

```csharp
Certmgr mgr = new Certmgr();
mgr.Cert = new Certificate(CertStoreTypes.cstPFXFile, @"C:\signingcert.pfx", "password", "*");
mgr.CertExtensions.Clear();
mgr.Config("CertUsageFlags=0xA0"); //Key Encipherment and Digital Signature
mgr.Config("CertExtendedKeyUsage=1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2"); //Server and Client authentication (respectively)
mgr.Config("CertValidityTime=10000");

Netcode nc = new Netcode();
nc.Format = NetcodeFormats.fmtHex;

// Set basicConstraints to be an end-entity.
// Below is the hex-encoded value broken down.
// 30     // Tag = sequence
// 03     // Length
//   01   // Tag = boolean
//   01   // Length
//     00 // False (not a CA)

// Convert hex string to byte[]
nc.EncodedData = "3003010100";
nc.Decode();

string oid = "2.5.29.19"; // basicConstraints
byte[] value = nc.DecodedDataB;
bool critical = false;
CertExtension basicConstraints = new CertExtension(oid, value, critical);
mgr.CertExtensions.Add(basicConstraints);

// Add one point: http://www.nsoftware.com/dummy/MyCA.crl
// Below is the hex-encoded value broken down.
// 30                    // Tag = sequence
// 2F                    // Length
//   30                  // Tag = DistributionPoint
//   2D                  // Length
//     A0                // Tag = DistributionPointName
//     2B                // Length
//       A0              // Tag = GeneralNames
//       29              // Length
//         86            // Tag = GeneralName
//         27            // Length
//           687474703A2F2F7777772E6E736F6674776172652E636F6D2F64756D6D792F4D7943412E63726C // URL

// Convert hex string to byte[]
nc.EncodedData = "302F302DA02BA0298627687474703A2F2F7777772E6E736F6674776172652E636F6D2F64756D6D792F4D7943412E63726C";
nc.Decode();

oid = "2.5.29.31"; // cRLDistributionPoints
value = nc.DecodedDataB;
critical = false;
CertExtension crlDistributionPoints = new CertExtension(oid, value, critical);
mgr.CertExtensions.Add(crlDistributionPoints);

mgr.IssueCertificate("CN=www.petsbymatilda.com", 123);
Console.WriteLine(mgr.Cert.Encoded);
```

## Constructors

```text
public CertExtension(string OID, byte[] value, bool critical);
```

# Certificate Type

This is the digital certificate being used.

## Remarks

This type describes the current digital certificate. The certificate may be a public or private key. The fields are used to identify or select certificates.

The following fields are available:

- [EffectiveDate](#Certificate_f_EffectiveDate)

- [ExpirationDate](#Certificate_f_ExpirationDate)

- [ExtendedKeyUsage](#Certificate_f_ExtendedKeyUsage)

- [Fingerprint](#Certificate_f_Fingerprint)

- [FingerprintSHA1](#Certificate_f_FingerprintSHA1)

- [FingerprintSHA256](#Certificate_f_FingerprintSHA256)

- [Issuer](#Certificate_f_Issuer)

- [PrivateKey](#Certificate_f_PrivateKey)

- [PrivateKeyAvailable](#Certificate_f_PrivateKeyAvailable)

- [PrivateKeyContainer](#Certificate_f_PrivateKeyContainer)

- [PublicKey](#Certificate_f_PublicKey)

- [PublicKeyAlgorithm](#Certificate_f_PublicKeyAlgorithm)

- [PublicKeyLength](#Certificate_f_PublicKeyLength)

- [SerialNumber](#Certificate_f_SerialNumber)

- [SignatureAlgorithm](#Certificate_f_SignatureAlgorithm)

- [Store](#Certificate_f_Store)

- [StorePassword](#Certificate_f_StorePassword)

- [StoreType](#Certificate_f_StoreType)

- [SubjectAltNames](#Certificate_f_SubjectAltNames)

- [ThumbprintMD5](#Certificate_f_ThumbprintMD5)

- [ThumbprintSHA1](#Certificate_f_ThumbprintSHA1)

- [ThumbprintSHA256](#Certificate_f_ThumbprintSHA256)

- [Usage](#Certificate_f_Usage)

- [UsageFlags](#Certificate_f_UsageFlags)

- [Version](#Certificate_f_Version)

- [Subject](#Certificate_f_Subject)

- [Encoded](#Certificate_f_Encoded)

## Fields

 **EffectiveDate** *string (read-only)*
Default: ""

The date on which this certificate becomes valid. Before this date, it is not valid. The date is localized to the system's time zone. The following example illustrates the format of an encoded date:

23-Jan-2000 15:00:00.

 **ExpirationDate** *string (read-only)*
Default: ""

The date on which the certificate expires. After this date, the certificate will no longer be valid. The date is localized to the system's time zone. The following example illustrates the format of an encoded date:

23-Jan-2001 15:00:00.

 **ExtendedKeyUsage** *string (read-only)*
Default: ""

A comma-delimited list of extended key usage identifiers. These are the same as ASN.1 object identifiers (OIDs).

 **Fingerprint** *string (read-only)*
Default: ""

The hex-encoded, 16-byte MD5 fingerprint of the certificate. This property is primarily used for keys which do not have a corresponding X.509 public certificate, such as PEM keys that only contain a private key. It is commonly used for SSH keys.

The following example illustrates the format: *bc:2a:72:af:fe:58:17:43:7a:5f:ba:5a:7c:90:f7:02*

 **FingerprintSHA1** *string (read-only)*
Default: ""

The hex-encoded, 20-byte SHA-1 fingerprint of the certificate. This property is primarily used for keys which do not have a corresponding X.509 public certificate, such as PEM keys that only contain a private key. It is commonly used for SSH keys.

The following example illustrates the format: *30:7b:fa:38:65:83:ff:da:b4:4e:07:3f:17:b8:a4:ed:80:be:ff:84*

 **FingerprintSHA256** *string (read-only)*
Default: ""

The hex-encoded, 32-byte SHA-256 fingerprint of the certificate. This property is primarily used for keys which do not have a corresponding X.509 public certificate, such as PEM keys that only contain a private key. It is commonly used for SSH keys.

The following example illustrates the format: *6a:80:5c:33:a9:43:ea:b0:96:12:8a:64:96:30:ef:4a:8a:96:86:ce:f4:c7:be:10:24:8e:2b:60:9e:f3:59:53*

 **Issuer** *string (read-only)*
Default: ""

The issuer of the certificate. This field contains a string representation of the name of the issuing authority for the certificate.

 **PrivateKey** *string (read-only)*
Default: ""

The private key of the certificate (if available). The key is provided as PEM/Base64-encoded data.

NOTE: The [PrivateKey](#Certificate_f_PrivateKey) may be available but not exportable. In this case, [PrivateKey](#Certificate_f_PrivateKey) returns an empty string.

 **PrivateKeyAvailable** *bool (read-only)*
Default: False

Whether a [PrivateKey](#Certificate_f_PrivateKey) is available for the selected certificate. If [PrivateKeyAvailable](#Certificate_f_PrivateKeyAvailable) is True, the certificate may be used for authentication purposes (e.g., server authentication).

 **PrivateKeyContainer** *string (read-only)*
Default: ""

The name of the [PrivateKey](#Certificate_f_PrivateKey) container for the certificate (if available). This functionality is available only on Windows platforms.

 **PublicKey** *string (read-only)*
Default: ""

The public key of the certificate. The key is provided as PEM/Base64-encoded data.

 **PublicKeyAlgorithm** *string (read-only)*
Default: ""

The textual description of the certificate's public key algorithm. The property contains either the name of the algorithm (e.g., "RSA" or "RSA_DH") or an object identifier (OID) string representing the algorithm.

 **PublicKeyLength** *int (read-only)*
Default: 0

The length of the certificate's public key (in bits). Common values are 512, 1024, and 2048.

 **SerialNumber** *string (read-only)*
Default: ""

The serial number of the certificate encoded as a string. The number is encoded as a series of hexadecimal digits, with each pair representing a byte of the serial number.

 **SignatureAlgorithm** *string (read-only)*
Default: ""

The text description of the certificate's signature algorithm. The property contains either the name of the algorithm (e.g., "RSA" or "RSA_MD5RSA") or an object identifier (OID) string representing the algorithm.

 **Store** *string*
Default: "MY"

The name of the certificate store for the client certificate.

The [StoreType](#Certificate_f_StoreType) field denotes the type of the certificate store specified by [Store](#Certificate_f_Store). If the store is password-protected, specify the password in [StorePassword](#Certificate_f_StorePassword).

[Store](#Certificate_f_Store) is used in conjunction with the [Subject](#Certificate_f_Subject) field to specify client certificates. If [Store](#Certificate_f_Store) has a value, and [Subject](#Certificate_f_Subject) or [Encoded](#Certificate_f_Encoded) is set, a search for a certificate is initiated. Please see the [Subject](#Certificate_f_Subject) field for details.

 Designations of certificate stores are platform dependent.

The following designations are the most common User and Machine certificate stores in Windows:

|  |  |
| --- | --- |
| MY | A certificate store holding personal certificates with their associated private keys. |
| CA | Certifying authority certificates. |
| ROOT | Root certificates. |

When the certificate store type is *cstPFXFile*, this property must be set to the name of the file. When the type is *cstPFXBlob*, the property must be set to the binary contents of a PFX file (i.e., PKCS#12 certificate store).

 **StoreB** *byte []*
Default: "MY"

The name of the certificate store for the client certificate.

The [StoreType](#Certificate_f_StoreType) field denotes the type of the certificate store specified by [Store](#Certificate_f_Store). If the store is password-protected, specify the password in [StorePassword](#Certificate_f_StorePassword).

[Store](#Certificate_f_Store) is used in conjunction with the [Subject](#Certificate_f_Subject) field to specify client certificates. If [Store](#Certificate_f_Store) has a value, and [Subject](#Certificate_f_Subject) or [Encoded](#Certificate_f_Encoded) is set, a search for a certificate is initiated. Please see the [Subject](#Certificate_f_Subject) field for details.

 Designations of certificate stores are platform dependent.

The following designations are the most common User and Machine certificate stores in Windows:

|  |  |
| --- | --- |
| MY | A certificate store holding personal certificates with their associated private keys. |
| CA | Certifying authority certificates. |
| ROOT | Root certificates. |

When the certificate store type is *cstPFXFile*, this property must be set to the name of the file. When the type is *cstPFXBlob*, the property must be set to the binary contents of a PFX file (i.e., PKCS#12 certificate store).

 **StorePassword** *string*
Default: ""

If the type of certificate store requires a password, this field is used to specify the password needed to open the certificate store.

 **StoreType** *CertStoreTypes*
Default: 0

The type of certificate store for this certificate.

 The component supports both public and private keys in a variety of formats. When the *cstAuto* value is used, the component will automatically determine the type. This field can take one of the following values:

|  |  |
| --- | --- |
| 0 (cstUser - default) | For Windows, this specifies that the certificate store is a certificate store owned by the current user. NOTE: This store type is not available in Java. |
| 1 (cstMachine) | For Windows, this specifies that the certificate store is a machine store. NOTE: This store type is not available in Java. |
| 2 (cstPFXFile) | The certificate store is the name of a PFX (PKCS#12) file containing certificates. |
| 3 (cstPFXBlob) | The certificate store is a string (binary or Base64-encoded) representing a certificate store in PFX (PKCS#12) format. |
| 4 (cstJKSFile) | The certificate store is the name of a Java Key Store (JKS) file containing certificates. NOTE: This store type is only available in Java. |
| 5 (cstJKSBlob) | The certificate store is a string (binary or Base64-encoded) representing a certificate store in Java Key Store (JKS) format. NOTE: This store type is only available in Java. |
| 6 (cstPEMKeyFile) | The certificate store is the name of a PEM-encoded file that contains a private key and an optional certificate. |
| 7 (cstPEMKeyBlob) | The certificate store is a string (binary or Base64-encoded) that contains a private key and an optional certificate. |
| 8 (cstPublicKeyFile) | The certificate store is the name of a file that contains a PEM- or DER-encoded public key certificate. |
| 9 (cstPublicKeyBlob) | The certificate store is a string (binary or Base64-encoded) that contains a PEM- or DER-encoded public key certificate. |
| 10 (cstSSHPublicKeyBlob) | The certificate store is a string (binary or Base64-encoded) that contains an SSH-style public key. |
| 11 (cstP7BFile) | The certificate store is the name of a PKCS#7 file containing certificates. |
| 12 (cstP7BBlob) | The certificate store is a string (binary) representing a certificate store in PKCS#7 format. |
| 13 (cstSSHPublicKeyFile) | The certificate store is the name of a file that contains an SSH-style public key. |
| 14 (cstPPKFile) | The certificate store is the name of a file that contains a PPK (PuTTY Private Key). |
| 15 (cstPPKBlob) | The certificate store is a string (binary) that contains a PPK (PuTTY Private Key). |
| 16 (cstXMLFile) | The certificate store is the name of a file that contains a certificate in XML format. |
| 17 (cstXMLBlob) | The certificate store is a string that contains a certificate in XML format. |
| 18 (cstJWKFile) | The certificate store is the name of a file that contains a JWK (JSON Web Key). |
| 19 (cstJWKBlob) | The certificate store is a string that contains a JWK (JSON Web Key). |
| 21 (cstBCFKSFile) | The certificate store is the name of a file that contains a BCFKS (Bouncy Castle FIPS Key Store). NOTE: This store type is only available in Java and .NET. |
| 22 (cstBCFKSBlob) | The certificate store is a string (binary or Base64-encoded) representing a certificate store in BCFKS (Bouncy Castle FIPS Key Store) format. NOTE: This store type is only available in Java and .NET. |
| 23 (cstPKCS11) | The certificate is present on a physical security key accessible via a PKCS#11 interface. To use a security key, create a new [Certificate](#certificate-type) object and pass cstPKCS11 as the [StoreType](#Certificate_f_StoreType), the full path of the PKCS#11 DLL as the [Store](#Certificate_f_Store), and the PIN as the [StorePassword](#Certificate_f_StorePassword). Code Example. SSH Authentication with Security Key (without CertMgr): sftp.SSHCert = new Certificate(CertStoreTypes.cstPKCS11, @"C:\Program Files\OpenSC Project\OpenSC\pkcs11\opensc-pkcs11.dll", "123456", // PIN "CN=cert_subject"); sftp.SSHUser = "test"; sftp.SSHLogon("myhost", 22); Alternatively, collect the necessary data using the [CertMgr](#certmgr-component) component by calling the [ListStoreCertificates](#liststorecertificates-method-certmgr-component) method after setting the corresponding properties accordingly. The certificate information returned in the [CertList](#certlist-event-certmgr-component) event's CertEncoded parameter may be saved for later use. When using a certificate obtained with this approach, pass the previously saved security key information as the [Store](#Certificate_f_Store) and set [StorePassword](#Certificate_f_StorePassword) to the PIN. Code Example. SSH Authentication with Security Key (with CertMgr): certmgr.CertStoreType = CertStoreTypes.cstPKCS11; certmgr.OnCertList += (s, e) => { secKeyBlob = e.CertEncoded; }; certmgr.CertStore = @"C:\Program Files\OpenSC Project\OpenSC\pkcs11\opensc-pkcs11.dll"; certmgr.CertStorePassword = "123456"; // PIN certmgr.ListStoreCertificates(); sftp.SSHCert = new Certificate(CertStoreTypes.cstPKCS11, secKeyBlob, "123456", "*"); sftp.SSHUser = "test"; sftp.SSHLogon("myhost", 22); |
| 99 (cstAuto) | The store type is automatically detected from the input data. This setting may be used with both public and private keys and can detect any of the supported formats automatically. |

 **SubjectAltNames** *string (read-only)*
Default: ""

Comma-separated lists of alternative subject names for the certificate.

 **ThumbprintMD5** *string (read-only)*
Default: ""

The MD5 hash of the certificate. It is primarily used for X.509 certificates. If the hash does not already exist, it is automatically computed.

 **ThumbprintSHA1** *string (read-only)*
Default: ""

The SHA-1 hash of the certificate. It is primarily used for X.509 certificates. If the hash does not already exist, it is automatically computed.

 **ThumbprintSHA256** *string (read-only)*
Default: ""

The SHA-256 hash of the certificate. It is primarily used for X.509 certificates. If the hash does not already exist, it is automatically computed.

 **Usage** *string (read-only)*
Default: ""

The text description of [UsageFlags](#Certificate_f_UsageFlags).

This value will be one or more of the following strings and will be separated by commas:

- Digital Signature
- Non-Repudiation
- Key Encipherment
- Data Encipherment
- Key Agreement
- Certificate Signing
- CRL Signing
- Encipher Only

If the provider is OpenSSL, the value is a comma-separated list of X.509 certificate extension names.

 **UsageFlags** *int (read-only)*
Default: 0

The flags that show intended use for the certificate. The value of [UsageFlags](#Certificate_f_UsageFlags) is a combination of the following flags:

|  |  |
| --- | --- |
| 0x80 | Digital Signature |
| 0x40 | Non-Repudiation |
| 0x20 | Key Encipherment |
| 0x10 | Data Encipherment |
| 0x08 | Key Agreement |
| 0x04 | Certificate Signing |
| 0x02 | CRL Signing |
| 0x01 | Encipher Only |

Please see the [Usage](#Certificate_f_Usage) field for a text representation of [UsageFlags](#Certificate_f_UsageFlags).

This functionality currently is not available when the provider is OpenSSL.

 **Version** *string (read-only)*
Default: ""

The certificate's version number. The possible values are the strings "V1", "V2", and "V3".

 **Subject** *string*
Default: ""

The subject of the certificate used for client authentication.

This field will be populated with the full subject of the loaded certificate. When loading a certificate, the subject is used to locate the certificate in the store.

If an exact match is not found, the store is searched for subjects containing the value of the property.

If a match is still not found, the property is set to an empty string, and no certificate is selected.

The special value "*" picks a random certificate in the certificate store.

The certificate subject is a comma-separated list of distinguished name fields and values. For instance, "CN=www.server.com, OU=test, C=US, E=example@email.com". Common fields and their meanings are as follows:

| Field | Meaning |
| --- | --- |
| CN | Common Name. This is commonly a hostname like www.server.com. |
| O | Organization |
| OU | Organizational Unit |
| L | Locality |
| S | State |
| C | Country |
| E | Email Address |

If a field value contains a comma, it must be quoted.

 **Encoded** *string*
Default: ""

The certificate (PEM/Base64 encoded). This field is used to assign a specific certificate. The [Store](#Certificate_f_Store) and [Subject](#Certificate_f_Subject) fields also may be used to specify a certificate.

When [Encoded](#Certificate_f_Encoded) is set, a search is initiated in the current [Store](#Certificate_f_Store) for the private key of the certificate. If the key is found, [Subject](#Certificate_f_Subject) is updated to reflect the full subject of the selected certificate; otherwise, [Subject](#Certificate_f_Subject) is set to an empty string.

 **EncodedB** *byte []*
Default: ""

The certificate (PEM/Base64 encoded). This field is used to assign a specific certificate. The [Store](#Certificate_f_Store) and [Subject](#Certificate_f_Subject) fields also may be used to specify a certificate.

When [Encoded](#Certificate_f_Encoded) is set, a search is initiated in the current [Store](#Certificate_f_Store) for the private key of the certificate. If the key is found, [Subject](#Certificate_f_Subject) is updated to reflect the full subject of the selected certificate; otherwise, [Subject](#Certificate_f_Subject) is set to an empty string.

## Constructors

```text
public Certificate();
```

 Creates a instance whose properties can be set.

```text
public Certificate(string certificateFile);
```

 Opens * CertificateFile * and reads out the contents as an X.509 public key.

```text
public Certificate(byte[] encoded);
```

 Parses * Encoded * as an X.509 public key.

```text
public Certificate(CertStoreTypes storeType, string store, string storePassword, string subject);
```

 * StoreType * identifies the type of certificate store to use. See for descriptions of the different certificate stores. * Store * is a file containing the certificate store. * StorePassword * is the password used to protect the store.

 After the store has been successfully opened, the component will attempt to find the certificate identified by * Subject * . This can be either a complete or a substring match of the X.509 certificate's subject Distinguished Name (DN). The * Subject * parameter can also take an MD5, SHA-1, or SHA-256 thumbprint of the certificate to load in a "Thumbprint=value" format.

```text
public Certificate(CertStoreTypes storeType, string store, string storePassword, string subject, string configurationString);
```

 * StoreType * identifies the type of certificate store to use. See for descriptions of the different certificate stores. * Store * is a file containing the certificate store. * StorePassword * is the password used to protect the store.

 * ConfigurationString * is a newline-separated list of name-value pairs that may be used to modify the default behavior. Possible values include "PersistPFXKey", which shows whether or not the PFX key is persisted after performing operations with the private key. This correlates to the PKCS12_NO_PERSIST_KEY CryptoAPI option. The default value is True (the key is persisted). "Thumbprint" - an MD5, SHA-1, or SHA-256 thumbprint of the certificate to load. When specified, this value is used to select the certificate in the store. This is applicable to the * cstUser * , * cstMachine * , * cstPublicKeyFile * , and * cstPFXFile * store types. "UseInternalSecurityAPI" shows whether the platform (default) or the internal security API is used when performing certificate-related operations.

 After the store has been successfully opened, the component will attempt to find the certificate identified by * Subject * . This can be either a complete or a substring match of the X.509 certificate's subject Distinguished Name (DN). The * Subject * parameter can also take an MD5, SHA-1, or SHA-256 thumbprint of the certificate to load in a "Thumbprint=value" format.

```text
public Certificate(CertStoreTypes storeType, string store, string storePassword, byte[] encoded);
```

 * StoreType * identifies the type of certificate store to use. See for descriptions of the different certificate stores. * Store * is a file containing the certificate store. * StorePassword * is the password used to protect the store.

 After the store has been successfully opened, the component will load * Encoded * as an X.509 certificate and search the opened store for a corresponding private key.

```text
public Certificate(CertStoreTypes storeType, byte[] store, string storePassword, string subject);
```

 * StoreType * identifies the type of certificate store to use. See for descriptions of the different certificate stores. * Store * is a byte array containing the certificate data. * StorePassword * is the password used to protect the store.

 After the store has been successfully opened, the component will attempt to find the certificate identified by * Subject * . This can be either a complete or a substring match of the X.509 certificate's subject Distinguished Name (DN). The * Subject * parameter can also take an MD5, SHA-1, or SHA-256 thumbprint of the certificate to load in a "Thumbprint=value" format.

```text
public Certificate(CertStoreTypes storeType, byte[] store, string storePassword, string subject, string configurationString);
```

 * StoreType * identifies the type of certificate store to use. See for descriptions of the different certificate stores. * Store * is a byte array containing the certificate data. * StorePassword * is the password used to protect the store.

 After the store has been successfully opened, the component will attempt to find the certificate identified by * Subject * . This can be either a complete or a substring match of the X.509 certificate's subject Distinguished Name (DN). The * Subject * parameter can also take an MD5, SHA-1, or SHA-256 thumbprint of the certificate to load in a "Thumbprint=value" format.

```text
public Certificate(CertStoreTypes storeType, byte[] store, string storePassword, byte[] encoded);
```

 * StoreType * identifies the type of certificate store to use. See for descriptions of the different certificate stores. * Store * is a byte array containing the certificate data. * StorePassword * is the password used to protect the store.

 After the store has been successfully opened, the component will load * Encoded * as an X.509 certificate and search the opened store for a corresponding private key.

# Config Settings ([CertMgr](#certmgr-component) Component)

 The component accepts one or more of the following *configuration settings*. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these *internal properties* is provided through the [Config](#config-method-certmgr-component) method.

### CertMgr Config Settings

**BasicConstraints**: The hex-encoded value of the certificate's Basic Constraints extension.This setting specifies the value of this certificate's Basic Constraints extension (as a hex-encoded string). This value is encoded according to the extension's ASN.1 specification. Setting this configuration setting is an alternative to creating a [CertExtension](#certextension-type) object, setting its [Value](#CertExtension_f_Value) field, and adding the object to [CertExtensions](#certextensions-property-certmgr-component).

```csharp
CertMgr certmgr = new CertMgr();
certmgr.Cert = new Certificate();
certmgr.CertStoreType = CertStoreTypes.cstUser;
certmgr.CertStore = "MY";
certmgr.Config("BasicConstraints=30030101FF");
certmgr.CreateCertificate(mySubject, 23);
```

**CertComment**: A comment to include in a saved certificate.This settings specifies the certificate comment when calling [ExportCertificate](#exportcertificate-method-certmgr-component). This setting is applicable only when [ExportFormat](#exportformat-property-certmgr-component) is set to one of the following values:

- OpenSSHKey ([ExportPrivateKey](#exportprivatekey-property-certmgr-component) must be False)
- SSH2PublicKey
- PPK

 When [ExportFormat](#exportformat-property-certmgr-component) is set to SSH2PublicKey, the value of this setting must be the full header (e.g., *Comment: My Comment*).

**CertExtendedKeyUsage**: The extended key usage of the certificate.This setting specifies the extended key usage flags of the certificate created by calling [CreateCertificate](#createcertificate-method-certmgr-component) or [IssueCertificate](#issuecertificate-method-certmgr-component). If specified, the value is a comma-separated list of OIDs. Common OIDs are as follows:

|  |  |
| --- | --- |
| 1.3.6.1.5.5.7.3.1 | Server Authentication |
| 1.3.6.1.5.5.7.3.2 | Client Authentication |
| 1.3.6.1.5.5.7.3.3 | Code Signing |
| 1.3.6.1.5.5.7.3.4 | Secure Email |
| 1.3.6.1.5.5.7.3.8 | Time Stamping |
| 1.3.6.1.5.5.7.3.9 | OCSP Signing |

For instance, the following value specified the extended key usage for Server Authentication, Client Authentication, and Code Signing: *1.3.6.1.5.5.7.3.1, 1.3.6.1.5.5.7.3.2, and 1.3.6.1.5.5.7.3.3*

**CertIssuerCertURL**: The URL where the issuing CA certificate can be obtained.The Authority Information Access (AIA) extension in X.509 certificates can be used to indicate the URL where the issuing Certificate Authority (CA) certificate can be obtained. If the extension is present for the loaded certificate, this configuration setting will contain the URL.

**CertKeyLength**: The public key length for created certificates and keys.When [CreateCertificate](#createcertificate-method-certmgr-component) creates a new certificate and associated key, or when [CreateKey](#createkey-method-certmgr-component) creates a key, this setting determines the length of the new public key (in bits). The default value is 2048.

**CertKeyType**: The types of keys created for new certificates.When [CreateCertificate](#createcertificate-method-certmgr-component) creates a new certificate and associated key, or when [CreateKey](#createkey-method-certmgr-component) creates a key, this setting determines the type of key generated: 1 for key exchange (encryption) keys, and 2 for digital signature keys. The default value is 1.

**CertPublicKeyAlgorithm**: The public key algorithm used when a certificate is created.When [CreateCertificate](#createcertificate-method-certmgr-component) creates a new certificate and associated key, this setting determines the public key algorithm of the generated keys. Following are the valid values:

- RSA (default)
- DSA
- ECDSA_P256
- ECDSA_P384
- ECDSA_P521
- ECDSA_Secp256k1
- ECDSA_Secp224k1
- ECDSA_Secp192k1
- ECDSA_Secp160k1
- ECDSA_BRAINPOOLP160R1
- ECDSA_BRAINPOOLP192R1
- ECDSA_BRAINPOOLP224R1
- ECDSA_BRAINPOOLP256R1
- ECDSA_BRAINPOOLP320R1
- ECDSA_BRAINPOOLP384R1
- ECDSA_BRAINPOOLP512R1
- ECDSA_BRAINPOOLP160T1
- ECDSA_BRAINPOOLP192T1
- ECDSA_BRAINPOOLP224T1
- ECDSA_BRAINPOOLP256T1
- ECDSA_BRAINPOOLP320T1
- ECDSA_BRAINPOOLP384T1
- ECDSA_BRAINPOOLP512T1
- Ed25519
- Ed448

**CertSignatureAlgorithm**: The signature algorithm used when creating certificates.When [CreateCertificate](#createcertificate-method-certmgr-component) or [IssueCertificate](#issuecertificate-method-certmgr-component) creates a new certificate, the signature algorithm used is specified by this setting. Following are the possible values:

- MD2
- MD5
- SHA1
- SHA256 (default)
- SHA384
- SHA512

**CertSubjectAltNames**: Subject Alternative Names for creating or issuing certificates.This allows the Subject Alternative Names extension to be specified when creating or issuing a certificate via [CreateCertificate](#createcertificate-method-certmgr-component) or [IssueCertificate](#issuecertificate-method-certmgr-component). This setting only supports email, DNS, URI, and IPv4 addresses. Separate alternative names should be separated by commas. For example:

```csharp
string altNames = "email:copy,dns:domain.com,dns.1:other.domain.com,uri:http://www.domain.com,ip:192.168.1.102"
```

**CertUsageFlags**: Sets the flags indicating the usage of the created certificate.This setting specifies the usage flags of the certificate created by calling [CreateCertificate](#createcertificate-method-certmgr-component) or [IssueCertificate](#issuecertificate-method-certmgr-component). If specified, the value is the binary OR of one or more of the supported values. For instance, a value of *12* or *0xC* is the binary OR of the Certificate Signing and Key Agreement usage flags. The following flags are supported:

|  |  |
| --- | --- |
| 0x80 | Digital Signature |
| 0x40 | Non-Repudiation |
| 0x20 | Key Encipherment |
| 0x10 | Data Encipherment |
| 0x08 | Key Agreement |
| 0x04 | Certificate Signing |
| 0x02 | CRL Signing |
| 0x01 | Encipher Only |

**CertValidityOffset**: The number of days until the certificate becomes valid.This configuration setting can be used to change when a newly created certificate becomes valid. By default, the certificate is valid as soon as it is created. Set [CertValidityOffset](#CertValidityOffset) to the number of days that this starting period should be offset from the current day. This setting also accepts negative values for back-dating the validity of a certificate. The default value is 0.

**CertValidityTime**: The validity period for the certificate.This configuration setting determines the duration in days that a newly created certificate remains valid. The certificate becomes valid as soon as it is created, unless [CertValidityOffset](#CertValidityOffset) is set. The duration is not changed if [CertValidityOffset](#CertValidityOffset) is set; the certificate will still expire [CertValidityTime](#CertValidityTime) days after the validity period begins. The default value is 365 days.

**CreatedKey**: The PKCS8 formatted private and public key pair created after calling CreateKey.This setting returns the PKCS8 formatted private and public key pair of the key created when [CreateKey](#createkey-method-certmgr-component) is called. This is useful in scenarios where exporting the key for use in another environment is required.

The private key may be assigned a key-specific password via this setting as shown.

```csharp
string createdKey = certmgr.Config("CreatedKey=private_key_password");
```

**CSP**: The Cryptographic Service Provider.The name of the Cryptographic Service Provider used to provide access to certificate signing operations.

**CSRKey**: The PKCS8 formatted private key to use when generating a CSR.This setting optionally specifies a PKCS8 formatted private key to use when calling [GenerateCSR](#generatecsr-method-certmgr-component). When set, the *keyName* parameter of [GenerateCSR](#generatecsr-method-certmgr-component) is ignored and the key specified by this setting is used instead.

**EncodeExportedCert**: Whether the certificate being exported to a string is encoded.This setting controls whether the certificate exported as a string when [ExportCertificate](#exportcertificate-method-certmgr-component) is called is encoded. If [ExportFormat](#exportformat-property-certmgr-component) is set to *PFX* or *P7B* before calling [ExportCertificate](#exportcertificate-method-certmgr-component) the exported certificate may be binary ([EncodeExportedCert](#EncodeExportedCert) is False), or base64 encoded ([EncodeExportedCert](#EncodeExportedCert) is True) to allow easier handling of the certificate data.

The default value is False.

**HasCRL**: Whether the certificate supports the CRL extension.This setting returns true if the currently loaded [Cert](#cert-property-certmgr-component) supports the CRL extension.

**HasOCSP**: Whether the certificate supports the OCSP extension.This setting returns true if the currently loaded [Cert](#cert-property-certmgr-component) supports the OCSP extension.

**ImportCertAction**: Specified the action to take if a matching certificate or a link to a matching certificate already exists.When calling [ImportCertificate](#importcertificate-method-certmgr-component) if a matching certificate or a link to a matching certificate already exists in the Windows certificate store this setting governs what action will be taken. Possible values are:

|  |  |
| --- | --- |
| 1 | CERT_STORE_ADD_NEW - Imports a certificate only if no existing certificate is present. |
| 2 | CERT_STORE_ADD_USE_EXISTING - If an existing certificate is found, it is not replaced. |
| 3 (default) | CERT_STORE_ADD_REPLACE_EXISTING - If an existing certificate is found it is replaced. |
| 4 | CERT_STORE_ADD_ALWAYS - No checks are performed and a new certificate is always added to the store. This can result in duplicates. |
| 5 | CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES - If an existing certificate is found it is replaced, and the new certificate inherits properties from the certificate it replaces. |
| 6 | CERT_STORE_ADD_NEWER - Imports a certificate only if the certificate is newer than an existing matching certificate. |
| 7 | CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES - Imports a certificate only if the certificate is newer than an existing matching certificate, and inherits the properties of old certificate it replaces. |

**ImportCertStoreType**: The type of certificate store being specified for import.When calling [ImportCertificate](#importcertificate-method-certmgr-component), this setting controls the type of the certificate being specified in the first parameter.

This config can take one of the following values:

|  |  |
| --- | --- |
| 2 (cstPFXFile) | The certificate store is the name of a PFX (PKCS12) file containing certificates. |
| 3 (cstPFXBlob) | The certificate store is a string (binary or base64-encoded) representing a certificate store in PFX (PKCS12) format. |
| 6 (cstPEMKeyFile) | The certificate store is the name of a PEM-encoded file that contains a private key and an optional certificate. |
| 7 (cstPEMKeyBlob) | The certificate store is a string (binary or base64-encoded) that contains a private key and an optional certificate. |
| 8 (cstPublicKeyFile) | The certificate store is the name of a file that contains a PEM- or DER-encoded public key certificate. |
| 9 (cstPublicKeyBlob) | The certificate store is a string (binary or base64-encoded) that contains a PEM- or DER-encoded public key certificate. |
| 10 (cstSSHPublicKeyBlob) | The certificate store is a string (binary or base64-encoded) that contains an SSH-style public key. |
| 13 (cstSSHPublicKeyFile) | The certificate store is the name of a file that contains an SSH-style public key. |
| 99 (cstAuto - default) | The certificate type is automatically determined from the input. |

 Note that this functionality is currently for Windows platforms only.

**JWKAlgorithm**: The JWK algorithm.This setting specifies the JWK algorithm. It can be set before calling [ExportCertificate](#exportcertificate-method-certmgr-component) (if [ExportFormat](#exportformat-property-certmgr-component) is set to *JWK*) to control the key algorithm used to create the JWK. This setting will also be populated after loading a JWK file.

Valid values are:

- *(empty string)*
- *HS256*
- *HS384*
- *HS512*
- *RS256*
- *RS384*
- *RS512*
- *EC256*
- *EC384*
- *EC512*
- *EC256K*

**JWKExportX5C**: Whether to export a certificate chain to the x5c parameter.When set to true, the component will attempt to build the X.509 certificate chain for the certificate currently selected by [Cert](#cert-property-certmgr-component). If successful, the x5c parameter will be added to the JWK. It can be set before calling [ExportCertificate](#exportcertificate-method-certmgr-component) (if [ExportFormat](#exportformat-property-certmgr-component) is set to *JWK*).

The default value is False.

**JWKKeyId**: The JWK key Id.This setting specifies the JWK key Id. It can be set before calling [ExportCertificate](#exportcertificate-method-certmgr-component) (if [ExportFormat](#exportformat-property-certmgr-component) is set to *JWK*). This setting will also be populated after loading a JWK file.

**JWKKeyOps**: The JWK intended key operations list.This setting specifies the intended key operations for the JWK. It can be set before calling [ExportCertificate](#exportcertificate-method-certmgr-component) (if [ExportFormat](#exportformat-property-certmgr-component) is set to *JWK*). This setting will also be populated after loading a JWK file.

This setting format is a JSON array. Examples: *["sign","verify"]* or *["encrypt"]*.

**JWKUse**: The JWK use parameter value.This setting specifies the intended usage of the key. It can be set before calling [ExportCertificate](#exportcertificate-method-certmgr-component) (if [ExportFormat](#exportformat-property-certmgr-component) is set to *JWK*). This setting will also be populated after loading a JWK file.

Valid values are *enc* and *sig*.

**KeyFormat**: How the public and private key are formatted.This setting controls the format of [PublicKey](#Certificate_f_PublicKey) and [PrivateKey](#Certificate_f_PrivateKey). By default these fields hold PEM formatted public and private key data. When set to 1 (XML) the keys are stored in a XML format. This only affects the values returned by the component; the actual keys remain the same regardless of this setting. Possible values are:

- 0 (PEM - default)
- 1 (XML)

 The default value is 0 (PEM).

**KSP**: The Key Storage Provider.The name of the Key Storage Provider used to store and create keys. By default, the value is *Microsoft Software Key Storage Provider*. To use the Trusted Platform Module (TPM), set this value to *Microsoft Platform Crypto Provider*.

**LogLevel**: The level of detail that is logged.This setting controls the level of detail that is logged through the [Log](#log-event-certmgr-component) event. Possible values are:

|  |  |
| --- | --- |
| 0 (None) | No events are logged. |
| 1 (Info - default) | Informational events are logged. |
| 2 (Verbose) | Detailed data are logged. |
| 3 (Debug) | Debug data are logged. |

**PFXCertEncryptionAlgorithm**: Certificate encryption algorithm used when exporting to PFX format.This setting specifies the algorithm used to encrypt the certificate when calling [ExportCertificate](#exportcertificate-method-certmgr-component), and is applicable only when [ExportFormat](#exportformat-property-certmgr-component) is set to *PFX* or *PKCS12*.

This setting takes one of the following values (either the OID or friendly name can be used):

|  |  |
| --- | --- |
| 2.16.840.1.101.3.4.1.42 | PBES2-AES-256-CBC (default) |
| 2.16.840.1.101.3.4.1.2 | PBES2-AES-128-CBC |
| 1.2.840.113549.3.7 | PBES2-DES-EDE3-CBC |
| 1.2.840.113549.1.12.1.1 | PBES1-RC4-128 |
| 1.2.840.113549.1.12.1.2 | PBES1-RC4-40 |
| 1.2.840.113549.1.12.1.3 | PBES1-3-KeyTripleDES-CBC |
| 1.2.840.113549.1.12.1.4 | PBES1-2-KeyTripleDES-CBC |
| 1.2.840.113549.1.12.1.5 | PBES1-RC2-128-CBC |
| 1.2.840.113549.1.12.1.6 | PBES1-RC2-40-CBC |

The default value of *PBES2-AES-256-CBC* is supported only on Windows Server 2019 and later, and Windows 10 version 1709 (Fall Creators Update) and later. On earlier versions where this default value is not supported, the component will automatically fall back to *PBES1-RC2-40-CBC*, ensuring compatibility without requiring any action.

**PFXKeyEncryptionAlgorithm**: Private key encryption algorithm used when exporting to PFX format.This setting specifies the algorithm used to encrypt the private key when calling [ExportCertificate](#exportcertificate-method-certmgr-component), and is applicable only when [ExportFormat](#exportformat-property-certmgr-component) is set to *PFX* or *PKCS12*.

This setting takes one of the following values (either the OID or friendly name can be used):

|  |  |
| --- | --- |
| 2.16.840.1.101.3.4.1.42 | PBES2-AES-256-CBC (default) |
| 2.16.840.1.101.3.4.1.2 | PBES2-AES-128-CBC |
| 1.2.840.113549.3.7 | PBES2-DES-EDE3-CBC |
| 1.2.840.113549.1.12.1.1 | PBES1-RC4-128 |
| 1.2.840.113549.1.12.1.2 | PBES1-RC4-40 |
| 1.2.840.113549.1.12.1.3 | PBES1-3-KeyTripleDES-CBC |
| 1.2.840.113549.1.12.1.4 | PBES1-2-KeyTripleDES-CBC |
| 1.2.840.113549.1.12.1.5 | PBES1-RC2-128-CBC |
| 1.2.840.113549.1.12.1.6 | PBES1-RC2-40-CBC |

The default value of *PBES2-AES-256-CBC* is supported only on Windows Server 2019 and later, and Windows 10 version 1709 (Fall Creators Update) and later. On earlier versions where this default value is not supported, the component will automatically fall back to *PBES1-RC2-40-CBC*, ensuring compatibility without requiring any action.

**ReplaceKey**: Whether or not to replace an existing key when creating a new key.If this is false (default), the component will throw an error if a duplicate key exists while generating a new keyset using [CreateKey](#createkey-method-certmgr-component). If set to true, the component will replace a key if it already exists when generating new keys.

**RequestSubjectAltNames**: Subject Alternative Names for a Certificate Signing Request. This allows Subject Alternative Names to be added to a Certificate Signing request. The setting only supports email, DNS, URI, and IPv4 addresses. Separate alternative names should be separated by commas. For example:

```csharp
string altNames = "email:copy,dns:domain.com,dns.1:other.domain.com,uri:http://www.domain.com,ip:192.168.1.102"
```

**TPMMigrationPassword**: The password for the certificate or key.This setting must be set before calling [CreateKey](#createkey-method-certmgr-component), [CreateCertificate](#createcertificate-method-certmgr-component), and [ImportCertificate](#importcertificate-method-certmgr-component) methods. The default value is an empty string. If this config is set, the private key in TPM can be exported via the ExportCertificate method with the correct password later. If the config is not set, the private key in TPM can never be exported from TPM. Below is a brief code example of how to use this configuration setting for importing and exporting certificates.

```csharp
// Initialize CertMgr component
Certmgr certmgr = new Certmgr();
certmgr.Config("UseInternalSecurityAPI=false");

// Specify TPM integration parameters
certmgr.CertStoreType = CertStoreTypes.cstUser;
certmgr.CertStore = "MY";
certmgr.Config("KSP=Microsoft Platform Crypto Provider");

// Import a certificate into the TPM
certmgr.ImportCertificate("path/to/certificate.pem", "password", "subject");
```

```csharp
// Initialize CertMgr component
Certmgr certmgr = new Certmgr();
certmgr.Config("UseInternalSecurityAPI=false");

// Specify TPM integration parameters
certmgr.CertStoreType = CertStoreTypes.cstUser;
certmgr.CertStore = "MY";
certmgr.Config("KSP=Microsoft Platform Crypto Provider");
certmgr.Config("TPMMigrationPassword=password");
certmgr.ExportPrivateKey = true;

// Create a certificate object
certmgr.Cert = new Certificate(CertStoreTypes.cstUser, "MY", "", rsaSubject);

// Export the certificate
certmgr.ExportCertificate("../path/to/cert", "password");
```

**X509Algorithm**: Public Key Algorithm OID.This setting exposes the Public Key Algorithm object identifier (OID) value for the currently loaded [Cert](#cert-property-certmgr-component).

**X509SignatureAlgorithm**: Signature Algorithm OID.This setting exposes the Signature Algorithm object identifier (OID) value for the currently loaded [Cert](#cert-property-certmgr-component).

### Base Config Settings

**BuildInfo**: Information about the product's build.When queried, this setting will return a string containing information about the product's build.

**GUIAvailable**: Whether or not a message loop is available for processing events.In a GUI-based application, long-running blocking operations may cause the application to stop responding to input until the operation returns. The component will attempt to discover whether or not the application has a message loop and, if one is discovered, it will process events in that message loop during any such blocking operation.

In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting [GUIAvailable](#GUIAvailable) to *false* will ensure that the component does not attempt to process external events.

**LicenseInfo**: Information about the current license.When queried, this setting will return a string containing information about the license this instance of a component is using. It will return the following information:

- Product: The product the license is for.
- Product Key: The key the license was generated from.
- License Source: Where the license was found (e.g., RuntimeLicense, License File).
- License Type: The type of license installed (e.g., Royalty Free, Single Server).
- Last Valid Build: The last valid build number for which the license will work.

**MaskSensitiveData**: Whether sensitive data is masked in log messages.In certain circumstances it may be beneficial to mask sensitive data, like passwords, in log messages. Set this to *true* to mask sensitive data. The default is *true*.

**UseInternalSecurityAPI**: Whether or not to use the system security libraries or an internal implementation. When set to *false*, the component will use the system security libraries by default to perform cryptographic functions where applicable. In this case, calls to unmanaged code will be made. In certain environments, this is not desirable. To use a completely managed security implementation, set this setting to *true*.

Setting this configuration setting to *true* tells the component to use the internal implementation instead of using the system security libraries.

 On Windows, this setting is set to *false* by default. On Linux/macOS, this setting is set to *true* by default.

NOTE: This setting is static. The value set is applicable to all components used in the application.

When this value is set, the product's system dynamic link library (DLL) is no longer required as a reference, as all unmanaged code is stored in that file.

# Trappable Errors ([CertMgr](#certmgr-component) Component)

### CertMgr Errors

|  |  |
| --- | --- |
| 143 | Busy executing current method. |
| 144 | No certificate selected. |
| 221 | Cannot acquire CSP. |
| 222 | Cannot generate key. |
| 270 | Cannot load specified security library. |
| 271 | Cannot open certificate store. |
| 272 | Cannot find specified certificate. |
| 274 | Cannot get certificate chain. |
| 275 | Cannot verify certificate chain. |
| 279 | Error enumerating certificate stores. |
| 280 | The certificate could not be decoded. |
| 281 | Cannot find security provider. |
| 282 | Cannot add certificate to store. |
| 283 | The certificate could not be encoded. |
| 285 | Cannot create certificate signing request. |
| 286 | Cannot acquire Issuer private key. |
| 287 | Cannot delete certificate. |
| 288 | Cannot export certificate. |
