---
product: Chilkat
product_version: 11.7.0
language: sqlserver
language_label: SQL Server
class: XmlCertVault
license: free
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/sqlserver_XmlCertVaultRef.html
---
# Chilkat XmlCertVault — SQL Server — v11.7.0

> Chilkat 11.7.0 · language=sqlserver · 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/sqlserver/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**

```sql
DECLARE @hr int
DECLARE @xmlCertVault int
EXEC @hr = sp_OACreate 'Chilkat.XmlCertVault', @xmlCertVault OUT
IF @hr <> 0
BEGIN
    PRINT 'Failed to create ActiveX component'
    RETURN
END

-- ... use @xmlCertVault ...

EXEC @hr = sp_OADestroy @xmlCertVault
```

T-SQL uses the Chilkat ActiveX through the OLE Automation stored procedures. They must be enabled once on the server (`EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;`), and the Chilkat ActiveX registered must match the bitness of the SQL Server instance (64-bit for a 64-bit SQL Server). To bind to a specific major version of Chilkat, append the major version number to the ProgID, such as `sp_OACreate 'Chilkat.XmlCertVault.11'` for Chilkat v11.\*.\*.

`sp_OACreate` returns an object token (an `int`) that is passed as the first argument of every `sp_OAMethod`, `sp_OAGetProperty` and `sp_OASetProperty` call, and released with `sp_OADestroy`. Objects returned by methods (such as an `HttpResponse` or `JsonObject`) are also tokens received through an `int` OUT parameter; they must likewise be destroyed, and the OUT parameter is `NULL` when the method fails to return an object. Objects passed as arguments are passed by their token. When an OLE Automation procedure itself fails (non-zero `@hr`), `sp_OAGetErrorInfo` describes the error.

Data types: strings are `nvarchar(4000)`; integers, booleans (1 or 0) and object tokens are `int`; dates are `datetime`. In the signatures on this page, `@success`, `@iResult`, `@sResult` and the like are the OUT variables receiving a method's return value, `@iValue` / `@sValue` receive or supply a property value, and the remaining `@` variables are the method's arguments in order.

A string returned through an OUT parameter is limited to 4000 characters. For longer values, retrieve the result as a result set into a table variable instead of an OUT parameter, for example `DECLARE @tmp TABLE (outputLine ntext)` followed by `INSERT INTO @tmp EXEC sp_OAGetProperty @xmlCertVault, 'LastErrorText'`. See [string length limitations for strings returned by sp_OAMethod calls](https://www.chilkatsoft.com/sql_server_nvarchar_max_limitation.asp).

Methods that pass or return raw byte arrays are not shown on this page, because `varbinary(max)` values cannot be exchanged through `sp_OAMethod` (see [varbinary(max) limitation](https://www.chilkatsoft.com/sql_server_varbinary_max_limitation.asp)). Use the `BinData`-based alternatives (methods ending in *Bd*) or the base64 / hex string-encoded variants instead. Binary *properties* (such as `LastBinaryResult`) can be retrieved as a result set into a table variable, as shown in their signatures. Asynchronous (*\*Async*) methods and event callbacks are not available from SQL Server.

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 SQL Server.

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` | `EXEC sp_OAGetProperty @xmlCertVault, 'DebugLogFilePath', @sValue OUT EXEC sp_OASetProperty @xmlCertVault, 'DebugLogFilePath', @sValue` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastBinaryResult` | `INSERT INTO @tmp EXEC sp_OAGetProperty @xmlCertVault, 'LastBinaryResult'` | read-only | This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. |
| `LastErrorHtml` | `EXEC sp_OAGetProperty @xmlCertVault, 'LastErrorHtml', @sValue OUT` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `EXEC sp_OAGetProperty @xmlCertVault, 'LastErrorText', @sValue OUT` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `EXEC sp_OAGetProperty @xmlCertVault, 'LastErrorXml', @sValue OUT` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `EXEC sp_OAGetProperty @xmlCertVault, 'LastMethodSuccess', @iValue OUT EXEC sp_OASetProperty @xmlCertVault, 'LastMethodSuccess', @iValue` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `LastStringResult` | `EXEC sp_OAGetProperty @xmlCertVault, 'LastStringResult', @sValue OUT` | read-only | In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. |
| `LastStringResultLen` | `EXEC sp_OAGetProperty @xmlCertVault, 'LastStringResultLen', @iValue OUT` | read-only | The length, in characters, of the string contained in the LastStringResult property. |
| `VerboseLogging` | `EXEC sp_OAGetProperty @xmlCertVault, 'VerboseLogging', @iValue OUT EXEC sp_OASetProperty @xmlCertVault, 'VerboseLogging', @iValue` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `EXEC sp_OAGetProperty @xmlCertVault, 'Version', @sValue OUT` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `MasterPassword` | property, read/write | `EXEC sp_OAGetProperty @xmlCertVault, 'MasterPassword', @sValue OUT EXEC sp_OASetProperty @xmlCertVault, 'MasterPassword', @sValue` |
| `AddCert` | method | `EXEC sp_OAMethod @xmlCertVault, 'AddCert', @success OUT, @cert` |
| `AddCertChain` | method | `EXEC sp_OAMethod @xmlCertVault, 'AddCertChain', @success OUT, @certChain` |
| `AddCertEncoded` | method | `EXEC sp_OAMethod @xmlCertVault, 'AddCertEncoded', @success OUT, @encodedBytes, @encoding` |
| `AddCertFile` | method | `EXEC sp_OAMethod @xmlCertVault, 'AddCertFile', @success OUT, @path` |
| `AddCertString` | method | `EXEC sp_OAMethod @xmlCertVault, 'AddCertString', @success OUT, @certData` |
| `AddPemFile` | method | `EXEC sp_OAMethod @xmlCertVault, 'AddPemFile', @success OUT, @path, @password` |
| `AddPfx` | method | `EXEC sp_OAMethod @xmlCertVault, 'AddPfx', @success OUT, @pfx` |
| `AddPfxEncoded` | method | `EXEC sp_OAMethod @xmlCertVault, 'AddPfxEncoded', @success OUT, @encodedBytes, @encoding, @password` |
| `AddPfxFile` | method | `EXEC sp_OAMethod @xmlCertVault, 'AddPfxFile', @success OUT, @path, @password` |
| `GetXml` | method | `EXEC sp_OAMethod @xmlCertVault, 'GetXml', @sResult OUT` |
| `LoadXml` | method | `EXEC sp_OAMethod @xmlCertVault, 'LoadXml', @success OUT, @xml` |
| `LoadXmlFile` | method | `EXEC sp_OAMethod @xmlCertVault, 'LoadXmlFile', @success OUT, @path` |
| `SaveXml` | method | `EXEC sp_OAMethod @xmlCertVault, 'SaveXml', @success OUT, @path` |

## Properties

### XmlCertVault.MasterPassword

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

```sql
EXEC sp_OAGetProperty @xmlCertVault, 'MasterPassword', @sValue OUT
EXEC sp_OASetProperty @xmlCertVault, 'MasterPassword', @sValue
```

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 · sqlserver · XmlCertVault · AddCert · method · since 9.5.0.40`

```sql
EXEC sp_OAMethod @xmlCertVault, 'AddCert', @success OUT, @cert
```

Adds a certificate to the XML vault.

Returns 1 for success, 0 for failure.

### XmlCertVault.AddCertChain

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'AddCertChain', @success OUT, @certChain
```

Adds a chain of certificates to the XML vault.

Returns 1 for success, 0 for failure.

### XmlCertVault.AddCertEncoded

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'AddCertEncoded', @success OUT, @encodedBytes, @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 1 for success, 0 for failure.

### XmlCertVault.AddCertFile

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'AddCertFile', @success OUT, @path
```

Adds a certificate to the XML vault.

Returns 1 for success, 0 for failure.

### XmlCertVault.AddCertString

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'AddCertString', @success OUT, @certData
```

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

Returns 1 for success, 0 for failure.

### XmlCertVault.AddPemFile

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'AddPemFile', @success OUT, @path, @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 1 for success, 0 for failure.

### XmlCertVault.AddPfx

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'AddPfx', @success OUT, @pfx
```

Adds a PFX (PKCS12) to the XML vault.

Returns 1 for success, 0 for failure.

### XmlCertVault.AddPfxEncoded

`Chilkat 11.7.0 · sqlserver · XmlCertVault · AddPfxEncoded · method`

```sql
EXEC sp_OAMethod @xmlCertVault, 'AddPfxEncoded', @success OUT, @encodedBytes, @encoding, @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 1 for success, 0 for failure.

### XmlCertVault.AddPfxFile

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'AddPfxFile', @success OUT, @path, @password
```

Adds a PFX file to the XML vault.

Returns 1 for success, 0 for failure.

### XmlCertVault.GetXml

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'GetXml', @sResult OUT
```

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

Returns `NULL` on failure

### XmlCertVault.LoadXml

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'LoadXml', @success OUT, @xml
```

Loads from an XML string.

Returns 1 for success, 0 for failure.

### XmlCertVault.LoadXmlFile

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'LoadXmlFile', @success OUT, @path
```

Loads from an XML file.

Returns 1 for success, 0 for failure.

### XmlCertVault.SaveXml

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

```sql
EXEC sp_OAMethod @xmlCertVault, 'SaveXml', @success OUT, @path
```

Saves the contents to an XML file.

Returns 1 for success, 0 for failure.

## Related classes

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

