Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex 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
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
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
MS Storage Providers
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
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

 

 

 

(DataFlex) PKCS11 Find Driver Files

See more PKCS11 Examples

Uses Chilkat's SCard class to find smartcards/tokens present on the system (Windows/Linux/Mac/etc.) to return information about the expected PKCS11 drivers (DLL, shared lib, dylib) and the confirmed existing PKCS11 drivers present on the system.

Once the PKCS11 driver file is discovered, it can be used as a starting point with the PKCS11 class, which is shown in this example.

Note: This example requires Chilkat v9.5.0.89 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoScard
    Variant vJson
    Handle hoJson
    Boolean iSuccess
    Variant vJson2
    Handle hoJson2
    Integer iNumExists
    String sPkcs11DriverPath
    Handle hoPkcs11
    Variant vJson
Pkcs11    Handle hoJsonPkcs11
    String sTemp1
    Boolean bTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // First discover the smart cards and tokens present on the system..
    Get Create (RefClass(cComChilkatSCard)) To hoScard
    If (Not(IsComObjectCreated(hoScard))) Begin
        Send CreateComObject of hoScard
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Set ComEmitCompact Of hoJson To False

    Get pvComObject of hoJson to vJson
    Get ComFindSmartcards Of hoScard vJson To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoScard To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1

    // Sample output:
    // Note: This example was tested on Windows, but it can also run on Linux and MacOSX.
    // Important: The information for "pkcs11_driver" was added in Chilkat v9.5.0.89.

    // {
    //   "reader": [
    //     {
    //       "name": "Gemalto USB SmartCard Reader 0",
    //       "state": "present,inuse",
    //       "vendorName": "Gemalto",
    //       "serialNumber": "3339424644374543",
    //       "systemName": "Gemalto USB SmartCard Reader 0",
    //       "card": {
    //         "atr": "3B7F96000080318065B084565110120FFE829000",
    //         "windows": {
    //           "miniDriver": "AxaltoCM.dll",
    //           "cryptoProvider": "Microsoft Base Smart Card Crypto Provider",
    //           "keyStorageProvider": "Microsoft Smart Card Key Storage Provider"
    //         },
    //         "pkcs11_driver": {
    //           "possible": [
    //             "C:/Program Files/SafeNet/Authentication/SAC/x64/IDPrimePKCS1164.dll",
    //             "C:/Program Files(x86)/Gemalto/IDGo 800 PKCS#11/IDPrimePKCS1164.dll",
    //             "C:/Program Files/Gemalto/IDGo 800 PKCS#11/IDPrimePKCS1164.dll",
    //             "C:/WINDOWS/SysWOW64/IDPrimePKCS1164.dll",
    //             "C:/WINDOWS/SysWOW64/eTPKCS11.dll"
    //           ],
    //           "exists": [
    //             "C:/Program Files/SafeNet/Authentication/SAC/x64/IDPrimePKCS1164.dll",
    //             "C:/WINDOWS/SysWOW64/eTPKCS11.dll"
    //           ]
    //         }
    //       }
    //     }
    //   ]
    // }

    // We're interested in the PKCS11 drivers that were found.

    // Find the 1st reader where the card is present.  (The "state" contains the keyword "present")
    Get ComFindRecord Of hoJson "reader" "state" "*present*" False To vJson2
    If (IsComObject(vJson2)) Begin
        Get Create (RefClass(cComChilkatJsonObject)) To hoJson2
        Set pvComObject Of hoJson2 To vJson2
    End
    Get ComLastMethodSuccess Of hoJson To bTemp1
    If (bTemp1 = False) Begin
        Showln "No readers exist with a smart card or token present."
        Procedure_Return
    End

    // Get the size of the "card.pkcs11_driver.exists" array.  
    // If it doesn't exist the size will be -1.
    Get ComSizeOfArray Of hoJson2 "card.pkcs11_driver.exists" To iNumExists
    If (iNumExists < 1) Begin
        Showln "No PKCS11 driver files found for the smart card."
        Send Destroy of hoJson2
        Procedure_Return
    End

    // Get the path of the 1st available PKCS11 driver.
    Get ComStringOf Of hoJson2 "card.pkcs11_driver.exists[0]" To sPkcs11DriverPath
    Showln "PKCS11 driver path = " sPkcs11DriverPath

    // Now that we have a driver file, we can use it for PKCS11 access..
    Get Create (RefClass(cComChilkatPkcs11)) To hoPkcs11
    If (Not(IsComObjectCreated(hoPkcs11))) Begin
        Send CreateComObject of hoPkcs11
    End

    Set ComSharedLibPath Of hoPkcs11 To sPkcs11DriverPath
    Send Destroy of hoJson2

    Get ComInitialize Of hoPkcs11 To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPkcs11 To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Get information about the smart card via PKCS11..
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonPkcs11
    If (Not(IsComObjectCreated(hoJsonPkcs11))) Begin
        Send CreateComObject of hoJsonPkcs11
    End
    Get pvComObject of hoJsonPkcs11 to vJsonPkcs11
    Get ComDiscover Of hoPkcs11 True vJsonPkcs11 To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPkcs11 To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Set ComEmitCompact Of hoJsonPkcs11 To False
    Get ComEmit Of hoJsonPkcs11 To sTemp1
    Showln sTemp1

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    // Sample output:

    // {
    //   "cryptokiVersion": {
    //     "major": 2,
    //     "minor": 20
    //   },
    //   "manufacturerID": "Gemalto",
    //   "libraryDescription": "Gemalto PKCS11",
    //   "libraryVersion": {
    //     "major": 10,
    //     "minor": 8
    //   },
    //   "slot": [
    //     {
    //       "id": 0,
    //       "slotDescription": "Gemalto USB SmartCard Reader 0",
    //       "manufacturerID": "Gemalto",
    //       "tokenPresent": true,
    //       "removableDevice": true,
    //       "hardwareSlot": true,
    //       "hardwareVersion": {
    //         "major": 0,
    //         "minor": 0
    //       },
    //       "firmwareVersion": {
    //         "major": 0,
    //         "minor": 0
    //       },
    //       "token": {
    //         "label": "chilkat",
    //         "manufacturerID": "Gemalto",
    //         "model": "ID Prime MD",
    //         "serialNumber": "2DD70CC46070255E",
    //         "flags": [
    //           "CKF_RNG",
    //           "CKF_LOGIN_REQUIRED",
    //           "CKF_USER_PIN_INITIALIZED",
    //           "CKF_DUAL_CRYPTO_OPERATIONS",
    //           "CKF_TOKEN_INITIALIZED",
    //           "CKF_SO_PIN_COUNT_LOW",
    //           "CKF_SO_PIN_LOCKED"
    //         ],
    //         "maxSessionCount": 0,
    //         "sessionCount": 0,
    //         "maxRwSessionCount": 0,
    //         "rwSessionCount": 0,
    //         "maxPinLen": 16,
    //         "minPinLen": 4,
    //         "totalPublicMemory": 32768,
    //         "freePublicMemory": 32720,
    //         "totalPrivateMemory": 32768,
    //         "freePrivateMemory": 32720,
    //         "hardwareVersion": {
    //           "major": 0,
    //           "minor": 0
    //         },
    //         "firmwareVersion": {
    //           "major": 0,
    //           "minor": 0
    //         },
    //         "utcTime": "",
    //         "mechanism": [
    //           "CKM_DES3_MAC",
    //           "CKM_DES3_MAC_GENERAL",
    //           "CKM_AES_MAC",
    //           "CKM_AES_MAC_GENERAL",
    //           "CKM_DES3_CBC",
    //           "CKM_DES3_CBC_PAD",
    //           "CKM_AES_CBC",
    //           "CKM_AES_CBC_PAD",
    //           "CKM_AES_CTR",
    //           "CKM_AES_CCM",
    //           "CKM_RSA_PKCS_KEY_PAIR_GEN",
    //           "CKM_RSA_PKCS",
    //           "CKM_RSA_PKCS_OAEP",
    //           "CKM_RSA_PKCS_PSS",
    //           "CKM_SHA256_RSA_PKCS_PSS",
    //           "CKM_SHA384_RSA_PKCS_PSS",
    //           "CKM_SHA512_RSA_PKCS_PSS",
    //           "CKM_SHA256_RSA_PKCS",
    //           "CKM_SHA384_RSA_PKCS",
    //           "CKM_SHA512_RSA_PKCS",
    //           "CKM_EC_KEY_PAIR_GEN",
    //           "CKM_ECDSA",
    //           "CKM_ECDSA_SHA256",
    //           "CKM_ECDSA_SHA384",
    //           "80000045",
    //           "CKM_ECDSA_SHA512",
    //           "CKM_ECDH1_DERIVE",
    //           "CKM_DES3_KEY_GEN",
    //           "CKM_AES_KEY_GEN",
    //           "CKM_PBE_SHA1_DES3_EDE_CBC",
    //           "CKM_GENERIC_SECRET_KEY_GEN",
    //           "CKM_PBA_SHA1_WITH_SHA1_HMAC",
    //           "CKM_PKCS5_PBKD2",
    //           "CKM_SHA_1_HMAC_GENERAL",
    //           "CKM_SHA_1_HMAC",
    //           "CKM_SHA256_HMAC_GENERAL",
    //           "CKM_SHA256_HMAC",
    //           "CKM_SHA384_HMAC_GENERAL",
    //           "CKM_SHA384_HMAC",
    //           "CKM_SHA512_HMAC_GENERAL",
    //           "CKM_SHA512_HMAC",
    //           "CKM_SHA_1",
    //           "CKM_SHA256",
    //           "CKM_SHA384",
    //           "CKM_SHA512",
    //           "80006001"
    //         ],
    //         "rsa": {
    //           "minKeySize": 2048,
    //           "maxKeySize": 2048
    //         }
    //       }
    //     }
    //   ]
    // }
    // 


End_Procedure

 

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