c++ - Get the X509 data from a PFX certificate using CryptoAPI -


good day. stackoverflow has helped me many times before, bit stuck on 1 , hope can give me pointers.

background: need pass x509 data of certificate adobe's sdk certlistcab in order sign pdf using acrobat plugin api.

my question how can x509 data pfx certificate using cryptoapi?

i've doing following:

  • converting pfx certificate in-memory store.

    crypt_data_blob data;

  • open file , populate data.

    file *fin = fopen("c:\\certificate\\mypfx.pfx", "rb")     fseek(fin, 0, seek_end);     data.cbdata = ftell(fin);     fseek(fin, 0, seek_set);     data.pbdata = (byte *)malloc(data.cbdata);     fread(data.pbdata, 1, data.cbdata, fin);     fclose(fin); 

    hcertstore hcertstore = pfximportcertstore(&data, l"password", 0);

  • find certificate. there one.

    pccert_context hcontext = certfindcertificateinstore (hcertstore, x509_asn_encoding | pkcs_7_asn_encoding, 0, cert_find_any, null, null);

  • get public key information certificate.

    bool bfreehandle; hcryptprov hprov; dword dwkeyspec; hcryptkey hcertpubkey; cryptacquirecertificateprivatekey (hcontext, 0, null, &hprov, &dwkeyspec, &bfreehandle);

    cryptimportpublickeyinfo(hprov, x509_asn_encoding | pkcs_7_asn_encoding, &hcontext->pcertinfo->subjectpublickeyinfo, &hcertpubkey));

  • now try make space x509 data.

    dword dwx509len; byte *x509data; cryptgetkeyparam(hcertpubkey,kp_certificate,null,&dwx509len,0);

    x509data = (byte*)malloc(dwx509len);

  • i pass in buffer.

    cryptgetkeyparam(hcertpubkey,kp_certificate,x509data,&dwx509len,0);

when run program receive error cryptgetkeyparam:

nte_bad_type : dwparam parameter specifies unknown value number.

according docs:

kp_certificate : pbdata address of buffer receives x.509 certificate has been encoded using distinguished encoding rules (der). public key in certificate must match corresponding signature or exchange key.

am doing wrong? there way obtain x509 data? appreciated.

regards, magda

looks i've over-complicated issue.

hcontext->pbcertencoded hcontext->cbcertencoded 

will give me data want.

still don't understand why using kp_certificate did not retrieve x509 data...


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -