---
product: Chilkat
product_version: 11.7.0
language: csharp
language_label: C#
class: XmlCertVault
license: free
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/csXmlCertVaultRef.html
---
# Chilkat XmlCertVault — C# — v11.7.0

> Chilkat 11.7.0 · language=csharp · class=XmlCertVault
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/XmlCertVault.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/csharp/guide.md`.

## Purpose

**Collect certificates, certificate chains, PEM data, and PFX private keys in an XML vault.**

`Chilkat.XmlCertVault` stores certificates and private-key material in a portable XML-based certificate vault. It can add individual certificates, certificate chains, DER or encoded certificates, PEM files, certificate strings, and PFX/PKCS12 data from files, memory, encoded text, or existing Chilkat objects. The vault can then be exported as XML, loaded from XML, or saved to an XML file for later reuse by other Chilkat certificate and TLS workflows.

**Add certificates**

Add certificates from `Cert` objects, files, PEM strings, binary DER bytes, or encoded data such as Base64 or hex.

**Add certificate chains**

Import an entire `CertChain` when related issuer and intermediate certificates should be kept together in the vault.

**Add PEM content**

Load PEM files containing one or more certificates and/or private keys, including encrypted PEM content when a password is supplied.

**Add PFX / PKCS12**

Add PFX data from a `Pfx` object, file, byte array, or encoded string, using the PFX password to import private-key material.

**Master password protection**

Use `MasterPassword` to protect access to private keys stored in the vault.

**Load and save XML**

Export the vault with `GetXml`, load it with `LoadXml` or `LoadXmlFile`, and persist it with `SaveXml`.

**Common pattern:** Create an `XmlCertVault`, set `MasterPassword` when the vault will contain private keys, add certificates or PFX/PEM material, then save the vault with `SaveXml` or keep the XML string from `GetXml`. Later, reload the same vault with `LoadXml` or `LoadXmlFile` and provide the same master password before using private keys.

**Security note:** Certificates are stored unencrypted, but private keys are stored using 256-bit AES encryption. The individual PFX passwords are also stored encrypted with the vault's `MasterPassword`, which is required to access any private keys contained in the XML vault.

## Object creation, unlocking and error handling

**Object Creation**

```csharp
Chilkat.XmlCertVault obj = new Chilkat.XmlCertVault();
```

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in C#.

Minimal complete program:

```csharp
// Required once per process. Any string unlocks a 30-day trial; use your purchased code in production.
Chilkat.Global glob = new Chilkat.Global();
if (!glob.UnlockBundle("Anything for 30-day trial"))
{
    Console.WriteLine(glob.LastErrorText);
    return;
}

Chilkat.XmlCertVault xmlCertVault = new Chilkat.XmlCertVault();

bool success = xmlCertVault.AddCertEncoded("<encodedBytes>", "<encoding>");
if (!success)
{
    Console.WriteLine(xmlCertVault.LastErrorText);   // full diagnostic of what went wrong
    return;
}
```

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `public string DebugLogFilePath {get; set; }` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastErrorHtml` | `public string LastErrorHtml {get; }` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `public string LastErrorText {get; }` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `public string LastErrorXml {get; }` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `public bool LastMethodSuccess {get; set; }` | read/write | Indicates the success or failure of the most recent method call: `true` means success, `false` means failure. |
| `VerboseLogging` | `public bool VerboseLogging {get; set; }` | read/write | If set to `true`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `public string Version {get; }` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `MasterPassword` | property, read/write | `public string MasterPassword {get; set; }` |
| `AddCert` | method | `public bool AddCert(Cert cert);` |
| `AddCertBinary` | method | `public bool AddCertBinary(byte[] certBytes);` |
| `AddCertChain` | method | `public bool AddCertChain(CertChain certChain);` |
| `AddCertEncoded` | method | `public bool AddCertEncoded(string encodedBytes, string encoding);` |
| `AddCertFile` | method | `public bool AddCertFile(string path);` |
| `AddCertString` | method | `public bool AddCertString(string certData);` |
| `AddPemFile` | method | `public bool AddPemFile(string path, string password);` |
| `AddPfx` | method | `public bool AddPfx(Pfx pfx);` |
| `AddPfxBinary` | method | `public bool AddPfxBinary(byte[] pfxBytes, string password);` |
| `AddPfxEncoded` | method | `public bool AddPfxEncoded(string encodedBytes, string encoding, string password);` |
| `AddPfxFile` | method | `public bool AddPfxFile(string path, string password);` |
| `GetXml` | method | `public string GetXml();` |
| `LoadXml` | method | `public bool LoadXml(string xml);` |
| `LoadXmlFile` | method | `public bool LoadXmlFile(string path);` |
| `SaveXml` | method | `public bool SaveXml(string path);` |

## Properties

### XmlCertVault.MasterPassword

`Chilkat 11.7.0 · csharp · XmlCertVault · MasterPassword · property · read/write · since 9.5.0.40`

```csharp
public string MasterPassword {get; set; }
```

The master password for the vault. Certificates are stored unencrypted, but private keys are stored 256-bit AES encrypted using the individual PFX passwords. The PFX passwords are stored 256-bit AES encrypted using the master password. The master password is required to acces any of the private keys stored within the XML vault.

## Methods

### XmlCertVault.AddCert

`Chilkat 11.7.0 · csharp · XmlCertVault · AddCert · method · since 9.5.0.40`

```csharp
public bool AddCert(Cert cert);
```

Adds a certificate to the XML vault.

Returns true for success, false for failure.

### XmlCertVault.AddCertBinary

`Chilkat 11.7.0 · csharp · XmlCertVault · AddCertBinary · method · since 9.5.0.40`

```csharp
public bool AddCertBinary(byte[] certBytes);
```

Adds a certificate to the XML vault from any binary format, such as DER.

Returns true for success, false for failure.

### XmlCertVault.AddCertChain

`Chilkat 11.7.0 · csharp · XmlCertVault · AddCertChain · method · since 9.5.0.40`

```csharp
public bool AddCertChain(CertChain certChain);
```

Adds a chain of certificates to the XML vault.

Returns true for success, false for failure.

### XmlCertVault.AddCertEncoded

`Chilkat 11.7.0 · csharp · XmlCertVault · AddCertEncoded · method · since 9.5.0.40`

```csharp
public bool AddCertEncoded(string encodedBytes, string encoding);
```

Adds a certificate to the XML vault where certificate is passed directly from encoded bytes (such as Base64, Hex, etc.). The encoding is indicated by `encoding`.

Returns true for success, false for failure.

### XmlCertVault.AddCertFile

`Chilkat 11.7.0 · csharp · XmlCertVault · AddCertFile · method · since 9.5.0.40`

```csharp
public bool AddCertFile(string path);
```

Adds a certificate to the XML vault.

Returns true for success, false for failure.

### XmlCertVault.AddCertString

`Chilkat 11.7.0 · csharp · XmlCertVault · AddCertString · method · since 9.5.0.40`

```csharp
public bool AddCertString(string certData);
```

Adds a certificate from any string representation format such as PEM.

Returns true for success, false for failure.

### XmlCertVault.AddPemFile

`Chilkat 11.7.0 · csharp · XmlCertVault · AddPemFile · method · since 9.5.0.40`

```csharp
public bool AddPemFile(string path, string password);
```

Adds the contents of a PEM file to the XML vault. The PEM file may be encrypted, and it may contain one or more certificates and/or private keys. The password is optional and only required if the PEM file contains encrypted content that requires a password.

Returns true for success, false for failure.

### XmlCertVault.AddPfx

`Chilkat 11.7.0 · csharp · XmlCertVault · AddPfx · method · since 9.5.0.40`

```csharp
public bool AddPfx(Pfx pfx);
```

Adds a PFX (PKCS12) to the XML vault.

Returns true for success, false for failure.

### XmlCertVault.AddPfxBinary

`Chilkat 11.7.0 · csharp · XmlCertVault · AddPfxBinary · method · since 9.5.0.40`

```csharp
public bool AddPfxBinary(byte[] pfxBytes, string password);
```

Adds a PFX to the XML vault where PFX is passed directly from in-memory binary bytes.

Returns true for success, false for failure.

### XmlCertVault.AddPfxEncoded

`Chilkat 11.7.0 · csharp · XmlCertVault · AddPfxEncoded · method`

```csharp
public bool AddPfxEncoded(string encodedBytes, string encoding, string password);
```

Adds a PFX to the XML vault where PFX is passed directly from encoded bytes (such as Base64, Hex, etc.). The encoding is indicated by `encoding`.

Returns true for success, false for failure.

### XmlCertVault.AddPfxFile

`Chilkat 11.7.0 · csharp · XmlCertVault · AddPfxFile · method · since 9.5.0.40`

```csharp
public bool AddPfxFile(string path, string password);
```

Adds a PFX file to the XML vault.

Returns true for success, false for failure.

### XmlCertVault.GetXml

`Chilkat 11.7.0 · csharp · XmlCertVault · GetXml · method · since 9.5.0.40`

```csharp
public string GetXml();
```

Returns the contents of the cert vault as an XML string.

Returns `null` on failure

### XmlCertVault.LoadXml

`Chilkat 11.7.0 · csharp · XmlCertVault · LoadXml · method · since 9.5.0.40`

```csharp
public bool LoadXml(string xml);
```

Loads from an XML string.

Returns true for success, false for failure.

### XmlCertVault.LoadXmlFile

`Chilkat 11.7.0 · csharp · XmlCertVault · LoadXmlFile · method · since 9.5.0.40`

```csharp
public bool LoadXmlFile(string path);
```

Loads from an XML file.

Returns true for success, false for failure.

### XmlCertVault.SaveXml

`Chilkat 11.7.0 · csharp · XmlCertVault · SaveXml · method · since 9.5.0.40`

```csharp
public bool SaveXml(string path);
```

Saves the contents to an XML file.

Returns true for success, false for failure.

## Related classes

[`Cert`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/csharp/classes/Cert.md), [`CertChain`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/csharp/classes/CertChain.md), [`Pfx`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/csharp/classes/Pfx.md)

