open-license-manager
2014-08-05 82d408374c8ece8f13b50b93ff24ab9633de14f0
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include "CryptoHelper.h"
 
void main() {
    CryptoHelper cryptoHlpr;
    BYTE *pbPublicKey = NULL, *pbPrivateKey = NULL;
    DWORD dwPublicKeySize = 0, dwPrivateKeySize = 0;
    HRESULT hr = S_OK;
    // Get the key container context.
    if (FAILED(hr = cryptoHlpr.AcquireContext((L"TestContainer")))) {
// Call FormatMessage to display the error returned in hr.
        return;
    }
    // Generate the public/private key pair.
    if (FAILED(hr = cryptoHlpr.GenerateKeyPair())) {
// Call FormatMessage to display the error returned in hr.
        return;
    }
    // Export out the public key blob.
    if (FAILED(
            hr = cryptoHlpr.ExportPublicKey(&pbPublicKey, dwPublicKeySize))) {
// Call FormatMessage to display the error returned in hr.
        return;
    }
    // Print out the public key to console as a
    // hexadecimal string.
    wprintf(L"\n\nPublicKey = \"");
    for (DWORD i = 0; i < dwPublicKeySize; i++) {
        wprintf(L"%02x", pbPublicKey[i]);
    }
    wprintf(L"\"\n");
    // Export out the private key blob.
    cryptoHlpr.ExportPrivateKey(&pbPrivateKey, dwPrivateKeySize);
    // Print out the private key to console as a
    // hexadecimal string.
    wprintf(L"\n\nPrivateKey = \"");
    for (i = 0; i < dwPrivateKeySize; i++) {
        wprintf(L"%02x", pbPrivateKey[i]);
    }
    wprintf(L"\"\n");
    // Delete the public key blob allocated by the
// ExportPublicKey method.
    if (pbPublicKey)
        delete[] pbPublicKey;
    // Delete the private key blob allocated by the
// ExportPrivateKey method.
    if (pbPrivateKey)
        delete[] pbPrivateKey;
    return;
}