Below you will see a code. I'm trying to convert some VB code into C++ and below is a start that I found on the Internet (it uses Crypt32.Lib) - It's ready, except for a few feautres. The "job" is to add the missing features below to the c++ code. These are the features:
1. User enters string through parameter, for example: 'hello'
Then in VB, somethine like "Chr$(0)" is being added at the end of that string. I'm not sure what Chr$(0) is though.
2. Now we have a string.
This string should now be base64 encoded.
3. With the new base64 encoded string, the VB program does the following (where sData is the base64 encoded string, and DataIn is a DATA_BLOB, see C++ source)
Dim abytFileData() As Byte
Dim abytDataOut() As Byte
abytFileData = StrConv(sData, vbFromUnicode) & Chr$(0)
DataIn.cbData = UBound(abytFileData) + 1
DataIn.pbData = VarPtr(abytFileData(0))
Now Im not sure what it does, but I believe it puts the encoded base64 string into a ByteArray, and then
it sets a length (?) of that ByteArray at the DataIn.cbData, and a pointer (?) at DataIn.pbdata to the ByteArray. Riiight?
4. Once that is done, it calls the function CryptProtectData, which is already programmed below.
5. Once it has called the function, VB does the following with the result:
ReDim abytDataOut(DataOut.cbData) As Byte
Call CopyMemory(DataOut(0), ByVal DataOut.pbData, DataOut.cbData)
Result = Chr$(3) & Chr$(4) & StrConv(abytDataOut, vbUnicode)
6. "Result" is now the result that I am looking for.
Any Idea how to get to that result?
So in summary, all I need is going from a User Input, to encoding that Input into base64, then using that to put it in a ByteArray, which is being used by a data_blob (DataIn), and then the data_blob is being used by CryptProtectData.
I would've given more points if possible. But if anyone is able to figure it out, I will appreciate a lot!
-- Here is the c++ code that I already have (requires crypt32.lib)
#define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
void MyHandleError(char *s);
BYTE *pbDataInput =(BYTE *)"Hello world of data protection.";
DWORD cbDataInput = strlen((char *)pbDataInput)+1;
DataIn.pbData = pbDataInput;
DataIn.cbData = cbDataInput;
LPWSTR pDescrOut = NULL;
printf("The data to be encrypted is: %s\n",pbDataInput);
printf("The encryption phase worked. \n");
void MyHandleError(char *s)
fprintf(stderr,"An error occurred in running the program. \n");
fprintf(stderr, "Error number %x.\n", GetLastError());
fprintf(stderr, "Program terminating. \n");