[英]C CryptUnprotectData crashes Program
Hi im trying to write a C Program that decrypts the Key that Chrome uses to encrypt saved Passwords.嗨,我正在尝试编写一个 C 程序来解密 Chrome 用来加密保存的密码的密钥。 The Key is encrypted with CryptProtectData and then encoded with Base64, i have sucessfully decoded the Key and now i want to decrypt it with CryptUnprotectData but when i try to use this function my Program just crashes, i had a similar Problem once when I got the size of the byte* holding the encrypted data wrong.密钥用 CryptProtectData 加密,然后用 Base64 编码,我已经成功解码了密钥,现在我想用 CryptUnprotectData 解密它,但是当我尝试使用这个功能时,我的程序崩溃了,当我得到一个类似的问题时保存错误的加密数据的字节 * 的大小。 Does anyone know what i did wrong?有谁知道我做错了什么?
#include <stdio.h>
#include <base64.h>
#include <wincrypt.h>
void main()
{
//RFBBUEk = DPAPI
char B64[] = "BAAAA0Iyd3wEV0RGMegDAT8KX6wEAAAAYUduGi5FwQr1+XlafMqBZAAAAAAIAAAAAABBmAAAAAQAAIAAAALIvW98pXJMaQ0aJPpr40c12oSSRDg59tr+zaF+podlvAAAAAA6AAAAAAgAAIAAAAD2z5W4nMDHLOxthH8nXyxl+1hpRdY2BGHStxaDvgjSiMAAAAIKrcLbXw5WZCPjqyPtO/3QahMa0yMRC/CoMS/OoDw5j7fcZ8N31sIildXpN82egDEAAAAAvzHS7+Zf2IR05cggu1XHfNGknq3TKRHW37CVEktIHHu6yo1K0Q0r5YevYDUUNdhzlpJ+ynQUTBAS2Fa3PRR4V";
int len = sizeof(B64);
int * flen;
char * ergebnis;
ergebnis = unbase64(B64,len,flen);
DATA_BLOB Input,Output;
Input.pbData = (byte*)ergebnis;
Input.cbData = *flen;
CryptUnprotectData(&Input,NULL,NULL,NULL,NULL,0,&Output);
printf("%s",(char*)Output.pbData);
getchar();
}
printf("%s",(char*)Output.pbData);
First, you don't check if CryptUnprotectData
succeeds.首先,您不检查CryptUnprotectData
成功。 If it fails, you're passing a pointer to garbage to printf
.如果失败,您将垃圾指针传递给printf
。
Second, how are you expecting printf
to know how many bytes to print?其次,您如何期望printf
知道要打印多少字节? You need to do something with Output.cbData
.您需要对Output.cbData
做一些事情。
Lastly, flen
is never assigned a value.最后, flen
永远不会被赋值。 You pass whatever nonsense, uninitialized value it has to unbase64
and then try to use that value.您将任何无意义的未初始化值传递给unbase64
,然后尝试使用该值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.