SOL9 Sample: CertStore

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * CertStore.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//2009/03/10

#include <sol\crypt\CryptServiceProvider.h>
#include <sol\crypt\CertStore.h>

void _tmain(int argc, TCHAR** argv)
{
  try {
    const wchar_t* SYSTEM_STORES[] = {L"Root", L"CA", L"ADDRESSBOOK", L"MY", L"Disallowed"};
    const int SYSTEM_STORES_SIZE = XtNumber(SYSTEM_STORES);
    
    CryptServiceProvider csp;
    {
      //Try to open system stores.  
      for (int i = 0; i<SYSTEM_STORES_SIZE; i++) {

        printf("SystemStore CertStore::open(L\"%S\")\n", SYSTEM_STORES[i]);
        CertStore certStore;
        certStore.open(csp,
          CERT_STORE_PROV_SYSTEM, 
          0, 
          CERT_SYSTEM_STORE_CURRENT_USER, 
          SYSTEM_STORES[i]);

        certStore.enumCertificates();
        printf("\n");

      }
    }

    const wchar_t* PHYSICAL_STORES[] = {L".Default", L".LocalMachine", L".GroupPolicy"};
    const int PHYSICAL_STORES_SIZE  = XtNumber(PHYSICAL_STORES);    
    {

      for (int i = 0; i<SYSTEM_STORES_SIZE; i++) {
        for (int j = 0; j<PHYSICAL_STORES_SIZE; j++) {
          wchar_t store[256];
          swprintf_s(store, SizeOf(store), L"%s\\%s", SYSTEM_STORES[i], PHYSICAL_STORES[j]);

          printf("PhysicalStore CertStore::open(L\"%S\")\n", store);
          try {
            CertStore certStore;
            certStore.open(csp,
              CERT_STORE_PROV_PHYSICAL, 
              0, 
              CERT_SYSTEM_STORE_CURRENT_USER, 
              store);

            certStore.enumCertificates();
            printf("\n");
          } catch (Exception& ex) {
            printf("\tException %s\n\n", ex.getErrorMessage());
          }
        }

      }
    }

  } catch (Exception& ex) {
    printf("Exception %s\n", ex.getErrorMessage());
  }
}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.