I am attempting to pass data from a sqlite3 file to CryptUnprotectData.
After selecting the data using a sqlite3 library I can print it to console. This is the data I am trying to decrypt (argv[i]):
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
hex(password_value) = 01000000D08C9DDF0115D1118C7A00C04FC297EB01000000EEB05AE6044E5749B7BB63FAB045C99C00000000020000000000106600000001000020000000F6027D9B2EA5742C36075600DDFA7ECDAFD55BE247F984FBC92BFC9C7F9DE9520000000000000000020000200000006EC519ACA4DA90EFA7149FF16502E0985F4B86C75F52A1EF7CAAAC5FC88E48CC10000000F0B305A4829F3D397F1379CD63EAB48F400000001BD5A3B07DAA31AE35A2FCE8BDDBBA28055307E3137B3EBE899C0A0AD35E905AE125FF0ACBCA2982169ABAB0AE899493446897297D47BA65A09115AB13821EFE
This is the prototype for the function that will decrypt:
BOOL WINAPI CryptUnprotectData(
__in DATA_BLOB *pDataIn,
__out_opt LPWSTR *ppszDataDescr,
__in_opt DATA_BLOB *pOptionalEntropy,
__in PVOID pvReserved,
__in_opt CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct,
__in DWORD dwFlags,
__out DATA_BLOB *pDataOut
);
DATA_BLOB struct looks like this:
typedef struct _CRYPTOAPI_BLOB {
DWORD cbData;
BYTE *pbData;
};
Where: cbData == A DWORD variable that contains the count, in bytes, of data. pbData == A pointer to the data buffer.
I think what I need to do is create a structure like this: DATA_BLOB DataEncrypted;
DataEncrypted.pbData = ??? DataEncrypted.cbData = strlen(argv[i])/2
and copy the data out of argv[i] into a byte-array... and then set pbData == pointer to byte array.
I'm not sure how to do the that part... any suggestions?