![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C) Find a Certificate by it's SHA-1 ThumbprintSee more Cert Store ExamplesFinds a certificate by it's SHA-1 hex thumbprint.Note: This example requires Chilkat v10.1.2 or later.
#include <C_CkCertStore.h> #include <C_CkJsonObject.h> #include <C_CkCert.h> void ChilkatSample(void) { HCkCertStore certStore; const char *thumbprint; BOOL bReadOnly; BOOL success; HCkJsonObject json; HCkCert cert; HCkCertStore certStorePem; certStore = CkCertStore_Create(); thumbprint = "12c1dd8015f3f03f7b1fa619dc24e2493ca8b4b2"; // This opens the Current User certificate store on Windows, // On MacOS and iOS it opens the default Keychain. bReadOnly = TRUE; success = CkCertStore_OpenCurrentUserStore(certStore,bReadOnly); if (success == FALSE) { printf("%s\n",CkCertStore_lastErrorText(certStore)); CkCertStore_Dispose(certStore); return; } // Find the certificate having a specific SHA1 thumbprint. json = CkJsonObject_Create(); CkJsonObject_UpdateString(json,"thumbprint",thumbprint); cert = CkCert_Create(); success = CkCertStore_FindCert(certStore,json,cert); if (success == FALSE) { printf("Failed to find the certificate.\n"); CkCertStore_Dispose(certStore); CkJsonObject_Dispose(json); CkCert_Dispose(cert); return; } printf("Found: %s\n",CkCert_subjectCN(cert)); // ------------------------------------------------------------------------------------- // Alternatively, one could load a certificate store object with certs from a PEM file, // and do the same thing.. certStorePem = CkCertStore_Create(); success = CkCertStore_LoadPemFile(certStorePem,"pemFiles/certificates.pem"); if (success == FALSE) { printf("%s\n",CkCertStore_lastErrorText(certStorePem)); CkCertStore_Dispose(certStore); CkJsonObject_Dispose(json); CkCert_Dispose(cert); CkCertStore_Dispose(certStorePem); return; } success = CkCertStore_FindCert(certStore,json,cert); if (success == FALSE) { printf("Failed to find the certificate.\n"); CkCertStore_Dispose(certStore); CkJsonObject_Dispose(json); CkCert_Dispose(cert); CkCertStore_Dispose(certStorePem); return; } printf("Found: %s\n",CkCert_subjectCN(cert)); CkCertStore_Dispose(certStore); CkJsonObject_Dispose(json); CkCert_Dispose(cert); CkCertStore_Dispose(certStorePem); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.