# MsCng X.509 Support
**API Group:** `xmlsec_mscng_x509`
X.509 certificate handling for the MsCng back-end.
X509 certificates verification support functions for MSCng.
X509 certificates implementation for MSCng. X509 certificates implementation for MSCng.
## Macros
### `xmlSecMSCngKeyDataX509Id`
*Defined as:* `xmlSecMSCngKeyDataX509GetKlass()`
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L28)
The MSCng X509 data klass.
---
### `xmlSecMSCngKeyDataRawX509CertId`
*Defined as:* `xmlSecMSCngKeyDataRawX509CertGetKlass()`
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L35)
The MSCng raw X509 certificate klass.
---
### `xmlSecMSCngX509StoreId`
*Defined as:* `xmlSecMSCngX509StoreGetKlass()`
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L42)
The MSCng X509 store klass.
---
## Functions
### `xmlSecMSCngKeyDataX509GetKlass`
```c
xmlSecKeyDataId xmlSecMSCngKeyDataX509GetKlass(void);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L30)
The MSCng X509 key data klass.
**Returns:** the X509 data klass.
---
### `xmlSecMSCngKeyDataRawX509CertGetKlass`
```c
xmlSecKeyDataId xmlSecMSCngKeyDataRawX509CertGetKlass(void);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L37)
The raw X509 certificates key data klass.
**Returns:** raw X509 certificates key data klass.
---
### `xmlSecMSCngX509StoreGetKlass`
```c
xmlSecKeyDataStoreId xmlSecMSCngX509StoreGetKlass(void);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L44)
The MSCng X509 certificates key data store klass.
**Returns:** pointer to MSCng X509 certificates key data store klass.
---
### `xmlSecMSCngKeyDataX509GetKeyCert`
```c
void * xmlSecMSCngKeyDataX509GetKeyCert(xmlSecKeyDataPtr data);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L46)
Gets the certificate from which the key was extracted.
**Parameters:**
- `data` — the pointer to X509 key data.
**Returns:** the key's certificate or NULL if key data was not used for key extraction or an error occurs.
---
### `xmlSecMSCngKeyDataX509AdoptKeyCert`
```c
int xmlSecMSCngKeyDataX509AdoptKeyCert(xmlSecKeyDataPtr data, void *cert);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L47)
Adds certificate to the X509 key data and sets the it as the key's.
**Parameters:**
- `data` — the pointer to key data.
- `cert` — the pointer to certificates.
certificate in `data`. On success, the `data` owns the cert.
**Returns:** 0 on success or a negative value otherwise.
---
### `xmlSecMSCngKeyDataX509AdoptCert`
```c
int xmlSecMSCngKeyDataX509AdoptCert(xmlSecKeyDataPtr data, void *cert);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L49)
Adds a certificate to `data`.
Adds `cert` to `data` as a certificate. On success, `data` owns the `cert`.
**Parameters:**
- `data` — the pointer to key data.
- `cert` — the pointer to certificates.
**Returns:** 0 on success or a negative value otherwise.
---
### `xmlSecMSCngKeyDataX509AdoptCrl`
```c
int xmlSecMSCngKeyDataX509AdoptCrl(xmlSecKeyDataPtr data, PCCRL_CONTEXT crl);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L51)
Adds CRL to the X509 key data.
**Parameters:**
- `data` — the pointer to X509 key data.
- `crl` — the pointer to MSCng X509 CRL.
**Returns:** 0 on success or a negative value if an error occurs.
---
### `xmlSecMSCngX509StoreAdoptCert`
```c
int xmlSecMSCngX509StoreAdoptCert(xmlSecKeyDataStorePtr store, void *cert, xmlSecKeyDataType type);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L53)
Adds trusted or untrusted certificate to the store.
Adds trusted (root) or untrusted certificate to the store.
**Parameters:**
- `store` — the pointer to X509 key data store klass.
- `pCert` — the pointer to PCCERT_CONTEXT X509 certificate.
- `type` — the certificate type (trusted/untrusted).
**Returns:** 0 on success or a negative value if an error occurs.
---
### `xmlSecMSCngX509StoreAdoptCrl`
```c
int xmlSecMSCngX509StoreAdoptCrl(xmlSecKeyDataStorePtr store, PCCRL_CONTEXT crl);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L56)
Adds CRL to the store for revocation checking.
**Parameters:**
- `store` — the pointer to X509 key data store klass.
- `crl` — the pointer to PCCRL_CONTEXT X509 CRL.
**Returns:** 0 on success or a negative value if an error occurs.
---
### `xmlSecMSCngX509StoreVerifyCrl`
```c
int xmlSecMSCngX509StoreVerifyCrl(xmlSecKeyDataStorePtr store, PCCRL_CONTEXT crl, xmlSecKeyInfoCtx *keyInfoCtx);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L66)
Verifies a CRL against trusted certificates in the store.
Verifies `crl` against the trusted certificates in `store`.
**Parameters:**
- `store` — the pointer to X509 key data store klass.
- `crl` — the pointer to CRL.
- `keyInfoCtx` — the pointer to key info context.
**Returns:** 1 if verified, 0 if not, or a negative value if an error occurs.
---
### `xmlSecMSCngX509StoreAdoptKeyStore`
```c
int xmlSecMSCngX509StoreAdoptKeyStore(xmlSecKeyDataStorePtr store, void *keyStore);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L69)
Adds `keyStore` to the list of key stores.
**Parameters:**
- `store` — the pointer to X509 key data store klass.
- `keyStore` — the pointer to keys store.
**Returns:** 0 on success or a negative value if an error occurs.
---
### `xmlSecMSCngX509StoreAdoptTrustedStore`
```c
int xmlSecMSCngX509StoreAdoptTrustedStore(xmlSecKeyDataStorePtr store, void *trustedStore);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L71)
Adds `trustedStore` to the trusted certs list.
Adds `trustedStore` to the list of trusted certs stores.
**Parameters:**
- `store` — the pointer to X509 key data store klass.
- `trustedStore` — the pointer to certs store.
**Returns:** 0 on success or a negative value if an error occurs.
---
### `xmlSecMSCngX509StoreAdoptUntrustedStore`
```c
int xmlSecMSCngX509StoreAdoptUntrustedStore(xmlSecKeyDataStorePtr store, void *untrustedStore);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L73)
Adds `trustedStore` to the untrusted certs list.
Adds `trustedStore` to the list of untrusted certs stores.
**Parameters:**
- `store` — the pointer to X509 key data store klass.
- `untrustedStore` — the pointer to certs store.
**Returns:** 0 on success or a negative value if an error occurs.
---
### `xmlSecMSCngX509StoreVerify`
```c
void * xmlSecMSCngX509StoreVerify(xmlSecKeyDataStorePtr store, void *certs, xmlSecKeyInfoCtx *keyInfoCtx);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L75)
Verifies `certs` list.
**Parameters:**
- `store` — the pointer to X509 certificate context store klass.
- `certs` — the untrusted certificates stack.
- `keyInfoCtx` — the pointer to element processing context.
**Returns:** pointer to the first verified certificate from `certs`.
---
### `xmlSecMSCngX509StoreFindCert`
```c
void * xmlSecMSCngX509StoreFindCert(xmlSecKeyDataStorePtr store, xmlChar *subjectName, xmlChar *issuerName, xmlChar *issuerSerial, xmlChar *ski, xmlSecKeyInfoCtx *keyInfoCtx);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L85)
Searches `store` for a certificate that matches given criteria.
**Parameters:**
- `store` — the pointer to X509 key data store klass.
- `subjectName` — the desired certificate name.
- `issuerName` — the desired certificate issuer name.
- `issuerSerial` — the desired certificate issuer serial number.
- `ski` — the desired certificate SKI.
- `keyInfoCtx` — the pointer to element processing context.
**Returns:** pointer to found certificate or NULL if certificate is not found or an error occurs.
---
### `xmlSecMSCngX509StoreFindCert_ex`
```c
void * xmlSecMSCngX509StoreFindCert_ex(xmlSecKeyDataStorePtr store, xmlChar *subjectName, xmlChar *issuerName, xmlChar *issuerSerial, xmlSecByte *ski, xmlSecSize skiSize, xmlSecKeyInfoCtx *keyInfoCtx);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L91)
Searches `store` for a certificate that matches given criteria.
**Parameters:**
- `store` — the pointer to X509 key data store klass.
- `subjectName` — the desired certificate name.
- `issuerName` — the desired certificate issuer name.
- `issuerSerial` — the desired certificate issuer serial number.
- `ski` — the desired certificate SKI.
- `skiSize` — the desired certificate SKI size.
- `keyInfoCtx` — the pointer to element processing context.
**Returns:** pointer to found certificate or NULL if certificate is not found or an error occurs.
---
### `xmlSecMSCngX509FindCertBySubject`
```c
void * xmlSecMSCngX509FindCertBySubject(void *store, char *wcSubject, unsigned\ long dwCertEncodingType);
```
*Source:* [include/xmlsec/mscng/x509.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/mscng/x509.h#L98)
Searches for a cert by `subject` in the store.
Searches for a cert with given `subject` in the `store`
**Parameters:**
- `store` — the pointer to certs store
- `wcSubject` — the cert subject (Unicode)
- `dwCertEncodingType` — the cert encoding type
**Returns:** cert handle on success or NULL otherwise
---