I get subject name from cert like this:
CertNameToStr(MY_ENCODING_TYPE,
&pCertContext->pCertInfo->Subject,
CERT_X500_NAME_STR,
pszNameString,
255);
then store it, and then try to find cert in the store:
CERT_NAME_BLOB subBlob;
subBlob.pbData = (BYTE*)subject; //unicode
subBlob.cbData = SysStringLen(subject);
PCCERT_CONTEXT pCert = CertFindCertificateInStore(hMYStoreHandle,
MY_ENCODING_TYPE,
0,
CERT_FIND_SUBJECT_NAME,
&subBlob,
NULL);
it allways fails (pCert == 0). I'm using WinXP Pro SP 2 with IE6.
Some code that should work:
// Get the name blob
CERT_NAME_BLOB suBlob;
suBlob.cbData = pCertContext->pCertInfo->Subject.cbData;
suBlob.pbData = new BYTE[suBlob.cbData];
if (NULL != suBlob.pbData) {
CopyMemory(suBlob.pbData, pCertContext->pCertInfo->Subject.pbData,
suBlob.cbData);
}
// Now persist the blob somewhere, and later find the cert using this blob
as you have below
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Petar Popara" <my....@mail.net> wrote in message
news:OR6hGU89...@TK2MSFTNGP15.phx.gbl...
CN=Badb, O=Baltimore Technologies, ST=Dublin, C=IE
and then to read it and find corresponding cert. I've tried this:
CERT_NAME_BLOB * subBlob;
DWORD subBlobLen = 0;
if (!CertStrToName(MY_ENCODING_TYPE,
"CN=Badb, O=Baltimore Technologies, ST=Dublin, C=IE",
CERT_X500_NAME_STR,
NULL,
NULL,
&subBlobLen,
NULL))
{
//error
}
subBlob = new CERT_NAME_BLOB[subBlobLen];
if (!CertStrToName(MY_ENCODING_TYPE,
"CN=Badb, O=Baltimore Technologies, ST=Dublin, C=IE",
CERT_X500_NAME_STR,
NULL,
(BYTE*)subBlob,
&subBlobLen,
NULL))
{
//error
}
if (!(pCert = CertFindCertificateInStore(hMYStoreHandle,
MY_ENCODING_TYPE,
0,
CERT_FIND_SUBJECT_NAME,
&subBlob,
NULL)))
{
//error
}
but it fails to find cert. :(