# MsCng Application Helpers

**API Group:** `xmlsec_mscng_app`

High-level application helpers for the MsCng back-end.

Application support functions for MSCng.

Common functions for the xmlsec1 command-line utility for the Microsoft Cryptography API: Next Generation (CNG).

## Functions

### `xmlSecMSCngAppInit`

```c
int xmlSecMSCngAppInit(const char *config);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L28)

Initializes the MSCng crypto engine.

General crypto engine initialization. This function is used by the XMLSec command-line utility and is called before the `xmlSecInit` function.

**Parameters:**

- `config` — the path to MSCng configuration (unused).


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppShutdown`

```c
int xmlSecMSCngAppShutdown(void);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L29)

Shuts down the MSCng crypto engine.

General crypto engine shutdown. This function is used by the XMLSec command-line utility and is called after the `xmlSecShutdown` function.

**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppGetCertStoreName`

```c
const char * xmlSecMSCngAppGetCertStoreName(void);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L30)

Gets the MSCng certs store name.

Gets the MS Cng certs store name set by `xmlSecMSCngAppInit` function.

**Returns:** the MS Cng certs name used by xmlsec-mscng.

---

### `xmlSecMSCngAppDefaultKeysMngrInit`

```c
int xmlSecMSCngAppDefaultKeysMngrInit(xmlSecKeysMngrPtr mngr);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L37)

Initializes the default key manager for MSCng.

Initializes `mngr` with simple keys store `xmlSecSimpleKeysStoreId` and a default MSCng crypto key data stores.

**Parameters:**

- `mngr` — the pointer to keys manager.


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppDefaultKeysMngrAdoptKey`

```c
int xmlSecMSCngAppDefaultKeysMngrAdoptKey(xmlSecKeysMngrPtr mngr, xmlSecKeyPtr key);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L38)

Adds `key` to the keys manager.

Adds `key` to the keys manager `mngr` created with `xmlSecMSCngAppDefaultKeysMngrInit` function.

**Parameters:**

- `mngr` — the pointer to keys manager.
- `key` — the pointer to key.


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppDefaultKeysMngrVerifyKey`

```c
int xmlSecMSCngAppDefaultKeysMngrVerifyKey(xmlSecKeysMngrPtr mngr, xmlSecKeyPtr key, xmlSecKeyInfoCtxPtr keyInfoCtx);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L40)

Verifies `key` using the keys manager.

Verifies `key` with the keys manager `mngr` created with `xmlSecCryptoAppDefaultKeysMngrInit` function:

- Checks that key certificate is present
- Checks that key certificate is valid

Adds `key` to the keys manager `mngr` created with `xmlSecCryptoAppDefaultKeysMngrInit` function.

**Parameters:**

- `mngr` — the pointer to keys manager.
- `key` — the pointer to key.
- `keyInfoCtx` — the key info context for verification.


**Returns:** 1 if key is verified, 0 otherwise, or a negative value if an error occurs.

---

### `xmlSecMSCngAppDefaultKeysMngrLoad`

```c
int xmlSecMSCngAppDefaultKeysMngrLoad(xmlSecKeysMngrPtr mngr, const char *uri);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L43)

Loads the XML keys file into the keys manager.

Loads XML keys file from `uri` to the keys manager `mngr` created with `xmlSecMSCngAppDefaultKeysMngrInit` function.

**Parameters:**

- `mngr` — the pointer to keys manager.
- `uri` — the uri.


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppDefaultKeysMngrSave`

```c
int xmlSecMSCngAppDefaultKeysMngrSave(xmlSecKeysMngrPtr mngr, const char *filename, xmlSecKeyDataType type);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L45)

Saves keys from `mngr` to XML keys file.

**Parameters:**

- `mngr` — the pointer to keys manager.
- `filename` — the destination filename.
- `type` — the type of keys to save (public/private/symmetric).


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppKeysMngrCertLoad`

```c
int xmlSecMSCngAppKeysMngrCertLoad(xmlSecKeysMngrPtr mngr, const char *filename, xmlSecKeyDataFormat format, xmlSecKeyDataType type);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L49)

Reads a cert from a file and adds to the key store.

Reads cert from `filename` and adds to the list of trusted or known untrusted certs in `store`.

**Parameters:**

- `mngr` — the keys manager.
- `filename` — the certificate file.
- `format` — the certificate file format.
- `type` — the flag that indicates is the certificate in `filename` trusted or not.


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppKeysMngrCertLoadMemory`

```c
int xmlSecMSCngAppKeysMngrCertLoadMemory(xmlSecKeysMngrPtr mngr, const xmlSecByte *data, xmlSecSize dataSize, xmlSecKeyDataFormat format, xmlSecKeyDataType type);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L53)

Reads cert from buffer and adds to the key store.

Reads cert from `data` and adds to the list of trusted or known untrusted certs in `store`.

**Parameters:**

- `mngr` — the pointer to keys manager.
- `data` — the certificate data.
- `dataSize` — the certificate data size.
- `format` — the certificate format (PEM or DER).
- `type` — the certificate type (trusted/untrusted).


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppKeysMngrCrlLoad`

```c
int xmlSecMSCngAppKeysMngrCrlLoad(xmlSecKeysMngrPtr mngr, const char *filename, xmlSecKeyDataFormat format);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L59)

Reads CRLs from a file and adds to the store.

Reads crls from `filename` and adds to the list of crls in `store`.

**Parameters:**

- `mngr` — the keys manager.
- `filename` — the CRL file.
- `format` — the CRL file format.


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppKeysMngrCrlLoadMemory`

```c
int xmlSecMSCngAppKeysMngrCrlLoadMemory(xmlSecKeysMngrPtr mngr, const xmlSecByte *data, xmlSecSize dataSize, xmlSecKeyDataFormat format);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L62)

Reads CRLs from memory and adds to the store.

Reads crls from `data` and adds to the list of crls in `store`.

**Parameters:**

- `mngr` — the pointer to keys manager.
- `data` — the CRL data.
- `dataSize` — the CRL data size.
- `format` — the CRL format (PEM or DER).


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppKeysMngrCrlLoadAndVerify`

```c
int xmlSecMSCngAppKeysMngrCrlLoadAndVerify(xmlSecKeysMngrPtr mngr, const char *filename, xmlSecKeyDataFormat format, xmlSecKeyInfoCtxPtr keyInfoCtx);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L66)

Loads and verifies a CRL from a file.

Atomically loads and verifies a CRL from `filename`.

**Parameters:**

- `mngr` — the keys manager.
- `filename` — the CRL filename.
- `format` — the CRL format (PEM or DER).
- `keyInfoCtx` — the key info context for verification parameters.


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppKeyLoadEx`

```c
xmlSecKeyPtr xmlSecMSCngAppKeyLoadEx(const char *filename, xmlSecKeyDataType type, xmlSecKeyDataFormat format, const char *pwd, void *pwdCallback, void *pwdCallbackCtx);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L78)

Reads a key from a file.

**Parameters:**

- `filename` — the key filename.
- `type` — the expected key type.
- `format` — the key file format.
- `pwd` — the key file password.
- `pwdCallback` — the key password callback.
- `pwdCallbackCtx` — the user context for password callback.


**Returns:** pointer to the key or NULL if an error occurs.

---

### `xmlSecMSCngAppKeyLoadMemory`

```c
xmlSecKeyPtr xmlSecMSCngAppKeyLoadMemory(const xmlSecByte *data, xmlSecSize dataSize, xmlSecKeyDataFormat format, const char *pwd, void *pwdCallback, void *pwdCallbackCtx);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L84)

Reads a key from the binary `data`.

**Parameters:**

- `data` — the key binary data.
- `dataSize` — the key binary data size.
- `format` — the key data format.
- `pwd` — the key data password.
- `pwdCallback` — the key password callback.
- `pwdCallbackCtx` — the user context for password callback.


**Returns:** pointer to the key or NULL if an error occurs.

---

### `xmlSecMSCngAppPkcs12Load`

```c
xmlSecKeyPtr xmlSecMSCngAppPkcs12Load(const char *filename, const char *pwd, void *pwdCallback, void *pwdCallbackCtx);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L91)

Reads key and certificates from PKCS12 file.

Reads a key and all associated certificates from the PKCS12 file. For uniformity, call `xmlSecMSCngAppKeyLoadEx` instead of this function. Pass in format=xmlSecKeyDataFormatPkcs12.

**Parameters:**

- `filename` — the PKCS12 key filename.
- `pwd` — the PKCS12 file password.
- `pwdCallback` — the password callback.
- `pwdCallbackCtx` — the user context for password callback.


**Returns:** pointer to the key or NULL if an error occurs.

---

### `xmlSecMSCngAppPkcs12LoadMemory`

```c
xmlSecKeyPtr xmlSecMSCngAppPkcs12LoadMemory(const xmlSecByte *data, xmlSecSize dataSize, const char *pwd, void *pwdCallback, void *pwdCallbackCtx);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L95)

Reads key and certs from PKCS12 binary data.

Reads a key and all associated certificates from the PKCS12 binary data. For uniformity, call `xmlSecMSCngAppKeyLoadEx` instead of this function. Pass in format=xmlSecKeyDataFormatPkcs12.

**Parameters:**

- `data` — the key binary data.
- `dataSize` — the key binary data size.
- `pwd` — the PKCS12 password.
- `pwdCallback` — the password callback.
- `pwdCallbackCtx` — the user context for password callback.


**Returns:** pointer to the key or NULL if an error occurs.

---

### `xmlSecMSCngAppKeyCertLoad`

```c
int xmlSecMSCngAppKeyCertLoad(xmlSecKeyPtr key, const char *filename, xmlSecKeyDataFormat format);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L100)

Reads the certificate from a file and adds to key.

Reads the certificate from `filename` and adds it to key.

**Parameters:**

- `key` — the pointer to key.
- `filename` — the certificate filename.
- `format` — the certificate file format.


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppKeyCertLoadMemory`

```c
int xmlSecMSCngAppKeyCertLoadMemory(xmlSecKeyPtr key, const xmlSecByte *data, xmlSecSize dataSize, xmlSecKeyDataFormat format);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L103)

Reads the certificate from memory and adds to key.

Reads the certificate from memory buffer and adds it to key.

**Parameters:**

- `key` — the pointer to key.
- `data` — the certificate binary data.
- `dataSize` — the certificate binary data size.
- `format` — the certificate file format.


**Returns:** 0 on success or a negative value otherwise.

---

### `xmlSecMSCngAppGetDefaultPwdCallback`

```c
void * xmlSecMSCngAppGetDefaultPwdCallback(void);
```

*Source:* [include/xmlsec/mscng/app.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/mscng/app.h#L109)

Gets default password callback.

**Returns:** default password callback.

---
