How to get certificate from pkcs7 file

0

I have a pkcs#7 file with included signers certificate, CA certificate, CRL. Now, to verify signature from this file I get the certificate from it. I try to do:

HANDLE hFile; 
if(!(hFile = CreateFile(L"c:\\users\\timur\\desktop\\sign_pkcs7.sig",
                            GENERIC_READ,
                            0,
                            NULL,
                            OPEN_EXISTING,
                            FILE_ATTRIBUTE_NORMAL,
                            NULL)))
{
    printf("Error opening file %d\n", GetLastError());
}

HCERTSTORE hPkcsStore = 0;
if(!(hPkcsStore = CertOpenStore(
                    CERT_STORE_PROV_PKCS7,
                    MY_TYPE,
                    NULL,
                    CERT_STORE_OPEN_EXISTING_FLAG,
                    hFile)))
{
    printf("Cert not found in pkcs7 store error %d.\n",GetLastError());
}

But while calling CertOpenStore program fails with Access violation reading location 0x0000001c.

c++
cryptoapi
pkcs#7
asked on Stack Overflow Feb 28, 2012 by forik

1 Answer

1

You can use CryptQueryObject to open the P7B file or files in many other formats (the code will be the same as here).

answered on Stack Overflow Mar 3, 2012 by Oleg • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0