0

I am a novice in C++ and started learning wincrypt yesterday. I have written this piece of code,

#pragma comment(lib, "crypt32.lib")

#include <iostream>
#include <windows.h>
#include <wincrypt.h>      // CryptoAPI definitions

using namespace std;

int main()
{
  string encMe = "password";
  HCRYPTKEY hKey;
  HCRYPTPROV hProv;
  PBYTE pbBuffer = NULL;


  CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_NEWKEYSET |     CRYPT_VERIFYCONTEXT);
  //cout << hex << GetLastError() << endl; DEBUG
  if(NTE_EXISTS == GetLastError())
    {
      CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT);
    }
  else if(0 == GetLastError())
    {
      cout << "Succes1" << endl;
    }


  CryptGenKey(hProv, CALG_AES_256, CRYPT_EXPORTABLE, &hKey);
  if(GetLastError() == 0)
  {
    cout << "Succes2" << endl;
    cout << hKey << endl;
 }

  cout << CryptEncrypt(hKey, 0, TRUE, 0, NULL, NULL, 1000) << endl;
  cout << GetLastError();
}

and I am stuck on the CryptEncrypt function. I read the MSDN page and have not understood anything after "hKey, 0, True, 0". Explain me for example what a 'A pointer to a buffer that contains the plaintext to be encrypted' is. Thank you in advance!

  • Windows SDK 7.x offers RSAKey sample \Samples\security\cryptoapi\encryptdecrypt\rsakey which features use of `CryptGenKey` and `CryptEncrypt`. – Roman R. Jul 15 '16 at 17:11
  • Thank you, but 1. I can't find the folder 2. I need the functions explained and some help with my AES code. – PePePlusPlus Jul 15 '16 at 22:04

0 Answers0