open-license-manager
2014-08-07 01a62b850a76916dae66f7f52e1d1e515584e7ce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <wincrypt.h>
#include <tchar.h>
 
// Helper class definition to generate and export Public/Private keys
// for Asymmetric encryption. The semantics for usage are:
// Call AcquireContext with a container name, call
// GenerateKeyPair next and then  call ExportPublicKey or
// ExportPrivateKey.
class CryptoHelper
{
private:
    HCRYPTPROV    m_hCryptProv;
public:
    HCRYPTKEY     m_hCryptKey;
    CryptoHelper();
    ~CryptoHelper();
    HRESULT AcquireContext(LPCTSTR wszContainerName);
    HRESULT GenerateKeyPair();
 
    HRESULT ExportPublicKey(BYTE **ppPublicKey, DWORD &cbKeySize);;
    HRESULT ExportPrivateKey(BYTE **ppPrivateKey, DWORD &cbKeySize);
};