title: Need help to find certificate by Subject name (X500 format, CERT_X500_NAME_STR) using CertFindCertificateInStore()?
body: <p>A client application has to access certificate from Windows certificate store. The search 
  input is the subject name in X500 string format as below.</p>
  
  <pre><code>"C=CH, S=Aargau, L=Baden, O=Test, OU=FF, CN= Test Root"
  </code></pre>
  
  <p>An exact match is required (not substring match using  CERT_FIND_SUBJECT_STR). 
  For this i do the following</p>
  
  <pre><code>CERT_NAME_BLOB subjectname = {0};
  
  /*convert the input X500 string to encoded subject name*/
  bRet = CertStrToNameA(X509_ASN_ENCODING, "C=CH, S=Aargau, L=Baden, O=Test, OU=S1, CN= Test Root", CERT_X500_NAME_STR, NULL, NULL, &amp;size, NULL);
    if(TRUE == bRet)
    {
       subjectname.pbData  = (BYTE*)malloc(size);
       subjectname.cbData = size;
  
       bRet = CertStrToNameA(X509_ASN_ENCODING , "C=CH, S=Aargau, L=Baden, O=Test, OU=S1, CN=Test Root", CERT_X500_NAME_STR, NULL, subjectname.pbData, &amp;subjectname.cbData, NULL);
       if(TRUE == bRet)
       {
            capiCertificate = CertFindCertificateInStore(hStore, X509_ASN_ENCODING, 0, CERT_FIND_SUBJECT_NAME, &amp;subjectname, NULL);
           if (NULL == capiCertificate)
           {
              errorcode = GetLastError();
              ret = CA_CERT_NOT_FOUND;
           }
       }
    }
  </code></pre>
  
  <p>The problem is that CertFindCertificateInStore always return NULL pointer. I have been debugging, but could not find out what is going wrong here.</p>
  
  <p>Any suggestions will be very helpful.</p>