Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

C++ Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Apple Keychain
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(C++) Open Smartcard Certificate Store (or from USB Token)

Demonstrates how to open the certificate store of the smart card currently in the reader (or the USB token). Iterates over the certs found on the smartcard.

Chilkat C/C++ Library Downloads

MS Visual C/C++

C++ Builder

Linux C/C++

Alpine Linux C/C++

MacOS C/C++

iOS C/C++

Android C/C++

MinGW C/C++

#include <CkCertStore.h>
#include <CkCert.h>

void ChilkatSample(void)
    {
    CkCertStore certStore;

    // Access the certificates on the smart card or USB token via the Chilkat certificate store class.
    // Note: Always pass the empty string to OpenSmartcard.

    // ---------------------------------------------------------------------------------------------------------
    // The following is true only for Chilkat v10.1.1 and earlier:
    // Also, the Chilkat CertStore class can only use MS CNG or CryptoAPI.
    // Some smartcard/USB token drivers only support PKCS11 or ScMinidriver.
    // You may get better results using Chilkat.Cert.LoadFromSmartcard because
    // Cert.LoadFromSmartcard can automatically detect and utilize PKCS11, ScMinidriver, CNG, and CryptoAPI.
    // ---------------------------------------------------------------------------------------------------------
    // Starting in Chilkat versions after v10.1.1, OpenSmartcard also works with
    // Apple Keychain and PKCS11 drivers on Windows, Linux, and MacOS.
    // ---------------------------------------------------------------------------------------------------------

    bool success = certStore.OpenSmartcard("");
    if (success == false) {
        std::cout << certStore.lastErrorText() << "\r\n";
        return;
    }

    std::cout << certStore.lastErrorText() << "\r\n";

    // Iterate over certificates on the smartcard.
    int i = 0;
    int numCerts = certStore.get_NumCertificates();
    std::cout << "numCerts = " << numCerts << "\r\n";

    while ((i < numCerts)) {
        CkCert *cert = certStore.GetCertificate(i);
        std::cout << cert->subjectCN() << "\r\n";
        std::cout << cert->serialNumber() << "\r\n";
        if (cert->IsRsa() == true) {
            std::cout << "key type is RSA" << "\r\n";
        }

        if (cert->IsEcdsa() == true) {
            std::cout << "key type is ECDSA" << "\r\n";
        }

        std::cout << "has private key: " << cert->HasPrivateKey() << "\r\n";
        std::cout << "----" << "\r\n";
        delete cert;
        i = i + 1;
    }
    }

 

© 2000-2025 Chilkat Software, Inc. All Rights Reserved.