[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-cryptoapi
Subject:    Re: Getting detailed information from the certificate
From:       Sorina Negulescu <sorina () SNARE ! COM>
Date:       1999-07-26 16:43:35
[Download RAW message or body]


>Is it possible to get and show detailed information
>of the certificate like IE is doing?
>
>For example, how to get the validity period for the
>certificate, the serial number and the thumbprint?



Assuming that you have a PCERT_CONTEXT pCertContext of the certificate:

1. Getting the effective date

CString csEffectiveDate;
 PCERT_INFO pCertificateInfo = pCertContext->pCertInfo;
 COleDateTime dt(pCertificateInfo->NotBefore);
 csEffectiveDate.Format("%s", dt.Format());

2. Getting the expiration date

CString csExpirationDate;
 PCERT_INFO pCertificateInfo = pCertContext->pCertInfo;
 COleDateTime dt(pCertificateInfo->NotAfter);
 csEffectiveDate.Format("%s", dt.Format());

3. Getting the serial number

 PCERT_INFO pCertifInfo = pCertContext->pCertInfo;
 BYTE* pbData = pCertifInfo->SerialNumber.pbData;
 DWORD cbData = pCertifInfo->SerialNumber.cbData;
 char hex_ascii[3];
 CString csAscii;
 csAscii.Empty();

// Now we have to convert the binary data into a string

 if (cbData > 0)
 {
  int i;
  CString cs;
  for (i=0; i < cbData; i++)
  {
   BYTE bb = (BYTE) pbData[i];
   sprintf(hex_ascii, "%02X", bb);
   cs.Format("%s", hex_ascii);
   if(csAscii.IsEmpty())
    csAscii = cs;
   else
    csAscii = cs + csAscii ;
  }
 }


4. Getting the thumbprint

 BYTE* pvData = NULL;
 DWORD cbData = 0L;

 BOOL bRet = CertGetCertificateContextProperty(
  pCertContext,
  CERT_MD5_HASH_PROP_ID,
  NULL,
  &cbData);
 if(bRet)
 {
  pvData = new BYTE[cbData];
  bRet = CertGetCertificateContextProperty(
  pCertContext,
  CERT_MD5_HASH_PROP_ID,
  pvData,
  &cbData);
 }

// Now we have to convert the binary data into a string
 char hex_ascii[3];
 CString csAscii;
 csAscii.Empty();

 if (cbData > 0)
 {
  int i;
  CString cs;
  for (i=0; i < cbData; i++)
  {
   BYTE bb = (BYTE) pvData[i];
   sprintf(hex_ascii, "%02X", bb);
   cs.Format("%s", hex_ascii);
   if(csAscii.IsEmpty())
    csAscii = cs;
   else
    csAscii = csAscii +cs;
  }
 }
 delete [] pvData;

----------------------------------------------------------------
Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://discuss.microsoft.com/archives/index.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic