如何将字符串复制到 CryptUnprotectData 的字节数组中
我正在尝试将数据从 sqlite3 文件传递到 CryptUnprotectData。
使用 sqlite3 库选择数据后,我可以将其打印到控制台。这是我试图解密的数据 (argv[i]):
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
hex(password_value) = 01000000D08C9DDF0115D1118C7A00C04FC297EB01000000EEB05AE6044E5749B7BB63FAB045C99C0000000002000000000010660000000100 0020000000F6027D9B2EA5742C36075600DDFA7ECDAFD55BE247F984FBC92BFC9C7F9DE9520000000000000000020000200000006EC519ACA4D A90EFA7149FF16502E0985F4B86C75F52A1EF7CAAAC5FC88E48CC10000000F0B305A4829F3D397F1379CD63EAB48F400000001BD5A3B07DAA3 1AE35A2FCE8BDDBBA28055307E3137B3EBE899C0A0AD35E905AE125FF0ACBCA2982169ABAB0AE899493446897297D47BA65A09115AB13821EFE
这是将解密的函数的原型:
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 结构如下所示:
typedef struct _CRYPTOAPI_BLOB {
DWORD cbData;
BYTE *pbData;
};
其中: cbData == 包含数据计数(以字节为单位)的 DWORD 变量。 pbData == 指向数据缓冲区的指针。
我认为我需要做的是创建一个像这样的结构: DATA_BLOB 数据加密;
数据加密.pbData = ??? DataEncrypted.cbData = strlen(argv[i])/2
并将数据从 argv[i] 复制到字节数组中...然后设置 pbData == 指向字节数组的指针。
我不知道如何做那部分......有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个很好的答案。虽然是Java语言,但是算法是一样的:
Here's a good answer. It's in Java, but the algorithm is the same: