How to correctly use CertFindCertificateInStore with needed parameters

Osman Zakir 121 Reputation points
2020-10-28T14:41:02.897+00:00

I marked the other question as solved because I figured that just knowing what function to use is enough for it. But I still need to know how to correctly use that function and how to pass it the information I need to pass it, so I decided to open a new thread since I wasn't getting a reply in the other one about it. I'm sorry if anyone has a problem with me doing this.

The certificates (it's a chain of two) I want to find use an encoding of SHA256. It apparently hasn't been defined so I can't tell the function to use it, but I don't know how to specify the encoding anyway. Is there an Enum I can use? What is that Enum and what member should I use from it?

What do I pass for dwFindFlags for the below dwFindType value that I want to use?

The dwFindType value I want to use is CERT_FIND_SUBJECT_CERT. How do I specify the specify "CERT_FIND_SUBJECT_CERT" as the argument for the parameter? It doesn't seem like I can just pass that in because it's telling me that it's undefined.

For dwFindPara I need to specify the actual structure with the certificate info, in this case, right? If I understand correctly. Again, though: I don't know how to do this. How do I specify the info from the certificate chain as DWORDs? I cant give them as strings.

For the last argument I think nullptr should be fine. Please correct me I'm wrong.

Anyway, please give me answers to the above questions. I need to know so I can correctly use the CertFindCertificateInStore function since right now I have no idea how to give it the info I want to give it. Please help me out here. Thanks.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,613 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,722 questions
Windows Server Security
Windows Server Security
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Security: The precautions taken to guard against crime, attack, sabotage, espionage, or another threat.
1,834 questions
{count} votes

2 answers

Sort by: Most helpful
  1. David Lowndes 4,716 Reputation points
    2020-10-28T15:08:35.867+00:00

    CERT_FIND_SUBJECT_CERT (not "CERT_FIND_SUBJECT_CERT") should be defined in wincrypt.h


  2. David Lowndes 4,716 Reputation points
    2020-10-28T15:32:52.48+00:00

    It's not something I've ever done, but see if this example helps.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.