open-license-manager
2014-08-06 425c196d0762424675120d92f9e4105d13af0f1a
1个文件已修改
52 ■■■■■ 已修改文件
src/bootstrap/win/Main.cpp 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/bootstrap/win/Main.cpp
@@ -1,13 +1,36 @@
#include <stdio.h>
#include "CryptoHelper.h"
#include <string>
void main() {
using namespace std;
void write_pubkey_file(string public_fname, BYTE *pbPublicKey, DWORD dwPublicKeySize){
    FILE* fp = fopen(public_fname.c_str(), "w");
    fprintf(fp, "//file generated by bootstrap.cpp, do not edit.\n\n");
    fprintf(fp, "#ifndef PUBLIC_KEY_H_\n#define PUBLIC_KEY_H_\n");
    fprintf(fp, "static BYTE PUBLIC_KEY[] = {");
    for (int i = 0; i < dwPublicKeySize; i++){
        if (i != 0){
            fprintf(fp, ",");
        }
        if (i % 15 == 0){
            fprintf(fp, "\n        ");
        }
        fprintf(fp, "%d", pbPublicKey[i]);
    }
    fprintf(fp, "\n};\n\n");
    fprintf(fp, "#define SHARED_RANDOM %d;\n", 12345);
    fprintf(fp, "#endif\n");
    fclose(fp);
}
void generatePk(string private_include, string public_include) {
    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")))) {
    if (FAILED(hr = cryptoHlpr.AcquireContext(_T("TestContainer")))) {
// Call FormatMessage to display the error returned in hr.
        return;
    }
@@ -22,6 +45,9 @@
// Call FormatMessage to display the error returned in hr.
        return;
    }
    else {
        write_pubkey_file(public_include, pbPublicKey, dwPublicKeySize);
    }
    // Print out the public key to console as a
    // hexadecimal string.
    wprintf(L"\n\nPublicKey = \"");
@@ -34,7 +60,7 @@
    // Print out the private key to console as a
    // hexadecimal string.
    wprintf(L"\n\nPrivateKey = \"");
    for (i = 0; i < dwPrivateKeySize; i++) {
    for (DWORD i = 0; i < dwPrivateKeySize; i++) {
        wprintf(L"%02x", pbPrivateKey[i]);
    }
    wprintf(L"\"\n");
@@ -48,3 +74,23 @@
        delete[] pbPrivateKey;
    return;
}
int main(int argc, char** argv) {
    if (argc != 3) {
        //print_usage();
        exit(2);
    }
    else {
        printf("********************************************\n");
        printf("*  Bootstrap!!!                            *\n");
        printf("********************************************\n");
    }
    string private_fname = string(argv[1]);
    string public_fname(argv[2]);
    generatePk(private_fname, public_fname);
    return 0;
}