baboso 0 Newbie Poster

Hi,

I want to download a certificate from a server to memory (i have to write in memory, can not create a file). Then i want to create a certificate with the "CryptQueryObject" function but it does not work and do not why?

any help?

bes regards

PCCERT_CONTEXT	pCertCtx		= NULL;

hINet = InternetOpen("Download", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); 
hFile = InternetOpenUrl(hINet, uri, NULL, 0, 0, 0 );
		
DWORD dwCertSize=3096; 
BYTE* certBuffer=new BYTE[dwCertSize];
memset(certBuffer,0,dwCertSize);
DWORD dwRead;

while ( InternetReadFile( hFile, certBuffer, 1023, &dwRead ) )
			{
				if ( dwRead == 0 )
					break;
				certBuffer[dwRead] = 0;

			}
			InternetCloseHandle( hFile );
			InternetCloseHandle( hINet );
			
			 blob.cbData = sizeof(certBuffer);
			 blob.pbData = certBuffer;

if (CryptQueryObject (
				CERT_QUERY_OBJECT_BLOB,
				&blob,
				CERT_QUERY_CONTENT_FLAG_ALL,
				CERT_QUERY_FORMAT_FLAG_ALL,
				0,
				NULL,
				NULL,
				NULL,
				NULL,
				NULL,
				(const void **)&pCertCtx) == 0)
			{
MyHandleError("CryptQueryObject fails");
}
An error occurred in running the program.
CryptQueryObject fails
Error number 0.
Program terminating.