| | |
| | | #include <stdio.h> |
| | | #include "CryptoHelper.h" |
| | | #include <string> |
| | | #include <stdlib.h> |
| | | #include <iostream> |
| | | |
| | | using namespace std; |
| | | |
| | |
| | | fprintf(fp, "%d", pbPublicKey[i]); |
| | | } |
| | | fprintf(fp, "\n};\n\n"); |
| | | fprintf(fp, "#define SHARED_RANDOM %d;\n", 12345); |
| | | int random = rand() % 1000; |
| | | fprintf(fp, "#define SHARED_RANDOM %d;\n", random); |
| | | fprintf(fp, "#endif\n"); |
| | | fclose(fp); |
| | | } |
| | | |
| | | void write_privkey_file(string private_fname, BYTE *privateKey, DWORD dwPrivateKeySize){ |
| | | FILE* fp = fopen(private_fname.c_str(), "w"); |
| | | fprintf(fp, "//file generated by bootstrap.cpp, do not edit.\n\n"); |
| | | fprintf(fp, "#ifndef PRIVATE_KEY_H_\n#define PRIVATE_KEY_H_\n"); |
| | | fprintf(fp, "static BYTE PRIVATE_KEY[] = {"); |
| | | for (int i = 0; i < dwPrivateKeySize; i++){ |
| | | if (i != 0){ |
| | | fprintf(fp, ","); |
| | | } |
| | | if (i % 15 == 0){ |
| | | fprintf(fp, "\n "); |
| | | } |
| | | fprintf(fp, "%d", privateKey[i]); |
| | | } |
| | | fprintf(fp, "\n};\n\n"); |
| | | fprintf(fp, "#endif\n"); |
| | | fclose(fp); |
| | | } |
| | |
| | | if (FAILED( |
| | | hr = cryptoHlpr.ExportPublicKey(&pbPublicKey, dwPublicKeySize))) { |
| | | // Call FormatMessage to display the error returned in hr. |
| | | cerr << "error exporting pubkey" << endl; |
| | | return; |
| | | } |
| | | else { |
| | |
| | | } |
| | | wprintf(L"\"\n"); |
| | | // Export out the private key blob. |
| | | cryptoHlpr.ExportPrivateKey(&pbPrivateKey, dwPrivateKeySize); |
| | | if (FAILED(cryptoHlpr.ExportPrivateKey(&pbPrivateKey, dwPrivateKeySize))){ |
| | | cerr << "Error exporting private key." << endl; |
| | | return; |
| | | } |
| | | else{ |
| | | write_privkey_file(private_include, pbPrivateKey, dwPrivateKeySize); |
| | | } |
| | | // Print out the private key to console as a |
| | | // hexadecimal string. |
| | | wprintf(L"\n\nPrivateKey = \""); |