# WinStd: Cryptography API

Cryptography API

## Classes

class | winstd::cert_context
| PCCERT_CONTEXT wrapper class. More...
class | winstd::cert_chain_context
| PCCERT_CHAIN_CONTEXT wrapper class. More...
class | winstd::cert_store
| HCERTSTORE wrapper class. More...
class | winstd::crypt_prov
| HCRYPTPROV wrapper class. More...
class | winstd::crypt_hash
| HCRYPTHASH wrapper class. More...
class | winstd::crypt_key
| HCRYPTKEY wrapper class. More...
class | winstd::data_blob
| DATA_BLOB wrapper class. More...

## Functions

template<class _Traits , class _Ax >
static DWORD | CertGetNameStringA (PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags, void *pvTypePara, std::basic_string< char, _Traits, _Ax > &sNameString)
| Obtains the subject or issuer name from a certificate CERT_CONTEXT structure and stores it in a std::wstring string. More...
template<class _Traits , class _Ax >
static DWORD | CertGetNameStringW (PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags, void *pvTypePara, std::basic_string< wchar_t, _Traits, _Ax > &sNameString)
| Obtains the subject or issuer name from a certificate CERT_CONTEXT structure and stores it in a std::wstring string. More...
template<class _Ty , class _Ax >
static BOOL WINAPI | CertGetCertificateContextProperty (PCCERT_CONTEXT pCertContext, DWORD dwPropId, std::vector< _Ty, _Ax > &aData)
| Retrieves the information contained in an extended property of a certificate context. More...
template<class _Ty , class _Ax >
static BOOL | CryptGetHashParam (HCRYPTHASH hHash, DWORD dwParam, std::vector< _Ty, _Ax > &aData, DWORD dwFlags)
| Retrieves data that governs the operations of a hash object. The actual hash value can be retrieved by using this function. More...
template<class T >
static BOOL | CryptGetHashParam (HCRYPTHASH hHash, DWORD dwParam, T &data, DWORD dwFlags)
| Retrieves data that governs the operations of a hash object. The actual hash value can be retrieved by using this function. More...
template<class _Ty , class _Ax >
static BOOL | CryptGetKeyParam (HCRYPTKEY hKey, DWORD dwParam, std::vector< _Ty, _Ax > &aData, DWORD dwFlags)
| Retrieves data that governs the operations of a key. More...
template<class T >
static BOOL | CryptGetKeyParam (HCRYPTKEY hKey, DWORD dwParam, T &data, DWORD dwFlags)
| Retrieves data that governs the operations of a key. More...
template<class _Ty , class _Ax >
static BOOL | CryptExportKey (HCRYPTKEY hKey, HCRYPTKEY hExpKey, DWORD dwBlobType, DWORD dwFlags, std::vector< _Ty, _Ax > &aData)
| Exports a cryptographic key or a key pair from a cryptographic service provider (CSP) in a secure manner. More...
template<class _Ty , class _Ax >
static BOOL | CryptEncrypt (HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, std::vector< _Ty, _Ax > &aData)
| Encrypts data. More...
template<class _Ty , class _Ax >
static BOOL | CryptDecrypt (HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, std::vector< _Ty, _Ax > &aData)
| Decrypts data previously encrypted by using the CryptEncrypt function. More...
static BOOL | CertGetCertificateChain (HCERTCHAINENGINE hChainEngine, PCCERT_CONTEXT pCertContext, LPFILETIME pTime, HCERTSTORE hAdditionalStore, PCERT_CHAIN_PARA pChainPara, DWORD dwFlags, LPVOID pvReserved, winstd::cert_chain_context &ctx)
| The CertGetCertificateChain function builds a certificate chain context starting from an end certificate and going back, if possible, to a trusted root certificate. More...
static BOOL | CryptAcquireContextA (winstd::crypt_prov &prov, LPCSTR szContainer, LPCSTR szProvider, DWORD dwProvType, DWORD dwFlags)
| Acquires the cryptographic context. More...
static BOOL | CryptAcquireContextW (winstd::crypt_prov &prov, LPCWSTR szContainer, LPCWSTR szProvider, DWORD dwProvType, DWORD dwFlags)
| Acquires the cryptographic context. More...
static BOOL | CryptCreateHash (HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, winstd::crypt_hash &hash)
| Creates the hash context. More...
static BOOL | CryptGenKey (HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, winstd::crypt_key &key)
| Generates the key. More...
static bool | CryptImportKey (HCRYPTPROV hProv, __in_bcount(dwDataLen) LPCBYTE pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, winstd::crypt_key &key)
| Imports the key. More...
static bool | CryptImportPublicKeyInfo (HCRYPTPROV hCryptProv, DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pInfo, winstd::crypt_key &key)
| Imports the public key. More...
static bool | CryptDeriveKey (HCRYPTPROV hProv, ALG_ID Algid, HCRYPTHASH hBaseData, DWORD dwFlags, winstd::crypt_key &key)
| Generates cryptographic session keys derived from a base data value. More...

## Detailed Description

## Function Documentation

## CertGetCertificateChain()

static BOOL CertGetCertificateChain | ( | HCERTCHAINENGINE | hChainEngine,
|  | PCCERT_CONTEXT | pCertContext,
|  | LPFILETIME | pTime,
|  | HCERTSTORE | hAdditionalStore,
|  | PCERT_CHAIN_PARA | pChainPara,
|  | DWORD | dwFlags,
|  | LPVOID | pvReserved,
|  | winstd::cert_chain_context & | ctx
| ) |  |

static

The CertGetCertificateChain function builds a certificate chain context starting from an end certificate and going back, if possible, to a trusted root certificate.

See also
  CertGetCertificateChain function

## CertGetCertificateContextProperty()

template<class _Ty , class _Ax >

static BOOL WINAPI CertGetCertificateContextProperty | ( | PCCERT_CONTEXT | pCertContext,
|  | DWORD | dwPropId,
|  | std::vector< _Ty, _Ax > & | aData
| ) |  |

static

Retrieves the information contained in an extended property of a certificate context.

See also
  CertGetCertificateContextProperty function

## CertGetNameStringA()

template<class _Traits , class _Ax >

static DWORD CertGetNameStringA | ( | PCCERT_CONTEXT | pCertContext,
|  | DWORD | dwType,
|  | DWORD | dwFlags,
|  | void * | pvTypePara,
|  | std::basic_string< char, _Traits, _Ax > & | sNameString
| ) |  |

static

Obtains the subject or issuer name from a certificate CERT_CONTEXT structure and stores it in a std::wstring string.

See also
  CertGetNameString function

## CertGetNameStringW()

template<class _Traits , class _Ax >

static DWORD CertGetNameStringW | ( | PCCERT_CONTEXT | pCertContext,
|  | DWORD | dwType,
|  | DWORD | dwFlags,
|  | void * | pvTypePara,
|  | std::basic_string< wchar_t, _Traits, _Ax > & | sNameString
| ) |  |

static

Obtains the subject or issuer name from a certificate CERT_CONTEXT structure and stores it in a std::wstring string.

See also
  CertGetNameString function

## CryptAcquireContextA()

static BOOL CryptAcquireContextA | ( | winstd::crypt_prov & | prov,
|  | LPCSTR | szContainer,
|  | LPCSTR | szProvider,
|  | DWORD | dwProvType,
|  | DWORD | dwFlags
| ) |  |

static

Acquires the cryptographic context.

See also
  CryptAcquireContext function

## CryptAcquireContextW()

static BOOL CryptAcquireContextW | ( | winstd::crypt_prov & | prov,
|  | LPCWSTR | szContainer,
|  | LPCWSTR | szProvider,
|  | DWORD | dwProvType,
|  | DWORD | dwFlags
| ) |  |

static

Acquires the cryptographic context.

See also
  CryptAcquireContext function

## CryptCreateHash()

static BOOL CryptCreateHash | ( | HCRYPTPROV | hProv,
|  | ALG_ID | Algid,
|  | HCRYPTKEY | hKey,
|  | DWORD | dwFlags,
|  | winstd::crypt_hash & | hash
| ) |  |

static

Creates the hash context.

See also
  CryptCreateHash function

## CryptDecrypt()

template<class _Ty , class _Ax >

static BOOL CryptDecrypt | ( | HCRYPTKEY | hKey,
|  | HCRYPTHASH | hHash,
|  | BOOL | Final,
|  | DWORD | dwFlags,
|  | std::vector< _Ty, _Ax > & | aData
| ) |  |

static

Decrypts data previously encrypted by using the CryptEncrypt function.

See also
  CryptDecrypt function

## CryptDeriveKey()

static bool CryptDeriveKey | ( | HCRYPTPROV | hProv,
|  | ALG_ID | Algid,
|  | HCRYPTHASH | hBaseData,
|  | DWORD | dwFlags,
|  | winstd::crypt_key & | key
| ) |  |

static

Generates cryptographic session keys derived from a base data value.

See also
  CryptDeriveKey function

## CryptEncrypt()

template<class _Ty , class _Ax >

static BOOL CryptEncrypt | ( | HCRYPTKEY | hKey,
|  | HCRYPTHASH | hHash,
|  | BOOL | Final,
|  | DWORD | dwFlags,
|  | std::vector< _Ty, _Ax > & | aData
| ) |  |

static

Encrypts data.

See also
  CryptEncrypt function

## CryptExportKey()

template<class _Ty , class _Ax >

static BOOL CryptExportKey | ( | HCRYPTKEY | hKey,
|  | HCRYPTKEY | hExpKey,
|  | DWORD | dwBlobType,
|  | DWORD | dwFlags,
|  | std::vector< _Ty, _Ax > & | aData
| ) |  |

static

Exports a cryptographic key or a key pair from a cryptographic service provider (CSP) in a secure manner.

See also
  CryptExportKey function

## CryptGenKey()

static BOOL CryptGenKey | ( | HCRYPTPROV | hProv,
|  | ALG_ID | Algid,
|  | DWORD | dwFlags,
|  | winstd::crypt_key & | key
| ) |  |

static

Generates the key.

See also
  CryptGenKey function

## CryptGetHashParam() [1/2]

template<class _Ty , class _Ax >

static BOOL CryptGetHashParam | ( | HCRYPTHASH | hHash,
|  | DWORD | dwParam,
|  | std::vector< _Ty, _Ax > & | aData,
|  | DWORD | dwFlags
| ) |  |

static

Retrieves data that governs the operations of a hash object. The actual hash value can be retrieved by using this function.

See also
  CryptGetHashParam function

## CryptGetHashParam() [2/2]

template<class T >

static BOOL CryptGetHashParam | ( | HCRYPTHASH | hHash,
|  | DWORD | dwParam,
|  | T & | data,
|  | DWORD | dwFlags
| ) |  |

static

Retrieves data that governs the operations of a hash object. The actual hash value can be retrieved by using this function.

See also
  CryptGetHashParam function

## CryptGetKeyParam() [1/2]

template<class _Ty , class _Ax >

static BOOL CryptGetKeyParam | ( | HCRYPTKEY | hKey,
|  | DWORD | dwParam,
|  | std::vector< _Ty, _Ax > & | aData,
|  | DWORD | dwFlags
| ) |  |

static

Retrieves data that governs the operations of a key.

See also
  CryptGetKeyParam function

## CryptGetKeyParam() [2/2]

template<class T >

static BOOL CryptGetKeyParam | ( | HCRYPTKEY | hKey,
|  | DWORD | dwParam,
|  | T & | data,
|  | DWORD | dwFlags
| ) |  |

static

Retrieves data that governs the operations of a key.

See also
  CryptGetKeyParam function

## CryptImportKey()

static bool CryptImportKey | ( | HCRYPTPROV | hProv,
|  | __in_bcount(dwDataLen) LPCBYTE | pbData,
|  | DWORD | dwDataLen,
|  | HCRYPTKEY | hPubKey,
|  | DWORD | dwFlags,
|  | winstd::crypt_key & | key
| ) |  |

static

Imports the key.

See also
  CryptImportKey function

## CryptImportPublicKeyInfo()

static bool CryptImportPublicKeyInfo | ( | HCRYPTPROV | hCryptProv,
|  | DWORD | dwCertEncodingType,
|  | PCERT_PUBLIC_KEY_INFO | pInfo,
|  | winstd::crypt_key & | key
| ) |  |

static

Imports the public key.

See also
  CryptImportPublicKeyInfo function