Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

MFC Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
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
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
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(MFC) ScMinidriver - Get Smartcard Properties

See more ScMinidriver Examples

Gets information about the smart card currently inserted in the reader (or USB token).

Note: This functionality was introduced in Chilkat v9.5.0.87.

Note: The ScMinidriver functionality is for Windows-only because ScMinidriver DLLs only exist on Windows. In the next version, Chilkat will be releasing a Pkcs11 class to support Linux, MacOSX, and possibly other operating systems.

Chilkat C/C++ Library Downloads

MS Visual C/C++ Libs

See Also: Using MFC CString in Chilkat

#include <CkScMinidriver.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    CkString strOut;

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

    CkScMinidriver scmd;

    // Reader names (smart card readers or USB tokens) can be discovered
    // via PCSC List Readers or PCSC Find Smart Cards
    const char *readerName = "Alcor Micro USB Smart Card Reader 0";
    bool success = scmd.AcquireContext(readerName);
    if (success == false) {
        strOut.append(scmd.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    CkJsonObject json;
    json.put_EmitCompact(false);

    success = scmd.GetCardProperties(json);
    if (success == false) {
        strOut.append(scmd.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    strOut.append(json.emit());
    strOut.append("\r\n");

    // Here is sample output:
    // See below for sample code to parse the JSON.
    // 
    // NOTE: Not all smart cards support all properties.
    // The GetCardProperties method will return information for all properties supported by the card.

    // {
    //   "bytesAvailable": 74752,
    //   "containersAvailable": 18,
    //   "maxKeyContainers": 20,
    //   "capabilities": {
    //     "fCertificateCompression": false,
    //     "fKeyGen": true
    //   },
    //   "keySizes": {
    //     "minimumBitlen": 2048,
    //     "defaultBitlen": 2048,
    //     "maximumBitlen": 4096,
    //     "incrementalBitlen": 1024
    //   },
    //   "readOnly": false,
    //   "cacheMode": "global",
    //   "supportsWinX509Enrollment": true,
    //   "guid": "1201803d-03e6-772a-3d80-0112e6032a77",
    //   "serial": "e6032a773d800112e6032a77",
    //   "pins": [
    //     "user",
    //     "admin",
    //     "role3",
    //     "role4"
    //   ],
    //   "pin": {
    //     "user": {
    //       "type": "regular",
    //       "purpose": "primaryCard",
    //       "changePermission": [
    //         "user"
    //       ],
    //       "unblockPermission": [
    //         "admin"
    //       ],
    //       "cachePolicy": "normal",
    //       "policyInfo": "00000000",
    //       "flags": "00000000",
    //       "acceptPlainTextPin": true,
    //       "generateSessionPin": false
    //     },
    //     "admin": {
    //       "type": "challenge/response",
    //       "purpose": "administrator",
    //       "changePermission": [
    //         "admin"
    //       ],
    //       "cachePolicy": "normal",
    //       "policyInfo": "00000000",
    //       "flags": "00000000"
    //     },
    //     "role3": {
    //       "type": "regular",
    //       "purpose": "digitalSignature",
    //       "changePermission": [
    //         "role3"
    //       ],
    //       "unblockPermission": [
    //         "role4"
    //       ],
    //       "cachePolicy": "alwaysPrompt",
    //       "policyInfo": "00000000",
    //       "flags": "00000000",
    //       "acceptPlainTextPin": true,
    //       "generateSessionPin": false
    //     },
    //     "role4": {
    //       "type": "regular",
    //       "purpose": "unblockOnly",
    //       "changePermission": [
    //         "role4"
    //       ],
    //       "cachePolicy": "normal",
    //       "policyInfo": "00000000",
    //       "flags": "00000000",
    //       "acceptPlainTextPin": true,
    //       "generateSessionPin": false
    //     }
    //   },
    //   "importSupport": [
    //     "plainText",
    //     "rsaKeyest",
    //     "eccKeyest",
    //     "symmetric"
    //   ],
    //   "algorithms": [
    //     "AES"
    //   ],
    //   "paddingSchemes": [
    //     "block",
    //     "pkcs1",
    //     "pss",
    //     "oaep"
    //   ],
    //   "chainingModes": [
    //     "ChainingModeCBC"
    //   ]
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    const char *strVal = 0;

    int bytesAvailable = json.IntOf("bytesAvailable");
    int containersAvailable = json.IntOf("containersAvailable");
    int maxKeyContainers = json.IntOf("maxKeyContainers");
    bool capabilitiesFCertificateCompression = json.BoolOf("capabilities.fCertificateCompression");
    bool capabilitiesFKeyGen = json.BoolOf("capabilities.fKeyGen");
    int keySizesMinimumBitlen = json.IntOf("keySizes.minimumBitlen");
    int keySizesDefaultBitlen = json.IntOf("keySizes.defaultBitlen");
    int keySizesMaximumBitlen = json.IntOf("keySizes.maximumBitlen");
    int keySizesIncrementalBitlen = json.IntOf("keySizes.incrementalBitlen");
    bool readOnly = json.BoolOf("readOnly");
    const char *cacheMode = json.stringOf("cacheMode");
    bool supportsWinX509Enrollment = json.BoolOf("supportsWinX509Enrollment");
    const char *guid = json.stringOf("guid");
    const char *serial = json.stringOf("serial");
    const char *pinUserType = json.stringOf("pin.user.type");
    const char *pinUserPurpose = json.stringOf("pin.user.purpose");
    const char *pinUserCachePolicy = json.stringOf("pin.user.cachePolicy");
    const char *pinUserPolicyInfo = json.stringOf("pin.user.policyInfo");
    const char *pinUserFlags = json.stringOf("pin.user.flags");
    bool pinUserAcceptPlainTextPin = json.BoolOf("pin.user.acceptPlainTextPin");
    bool pinUserGenerateSessionPin = json.BoolOf("pin.user.generateSessionPin");
    const char *pinAdminType = json.stringOf("pin.admin.type");
    const char *pinAdminPurpose = json.stringOf("pin.admin.purpose");
    const char *pinAdminCachePolicy = json.stringOf("pin.admin.cachePolicy");
    const char *pinAdminPolicyInfo = json.stringOf("pin.admin.policyInfo");
    const char *pinAdminFlags = json.stringOf("pin.admin.flags");
    const char *pinRole3Type = json.stringOf("pin.role3.type");
    const char *pinRole3Purpose = json.stringOf("pin.role3.purpose");
    const char *pinRole3CachePolicy = json.stringOf("pin.role3.cachePolicy");
    const char *pinRole3PolicyInfo = json.stringOf("pin.role3.policyInfo");
    const char *pinRole3Flags = json.stringOf("pin.role3.flags");
    bool pinRole3AcceptPlainTextPin = json.BoolOf("pin.role3.acceptPlainTextPin");
    bool pinRole3GenerateSessionPin = json.BoolOf("pin.role3.generateSessionPin");
    const char *pinRole4Type = json.stringOf("pin.role4.type");
    const char *pinRole4Purpose = json.stringOf("pin.role4.purpose");
    const char *pinRole4CachePolicy = json.stringOf("pin.role4.cachePolicy");
    const char *pinRole4PolicyInfo = json.stringOf("pin.role4.policyInfo");
    const char *pinRole4Flags = json.stringOf("pin.role4.flags");
    bool pinRole4AcceptPlainTextPin = json.BoolOf("pin.role4.acceptPlainTextPin");
    bool pinRole4GenerateSessionPin = json.BoolOf("pin.role4.generateSessionPin");
    int i = 0;
    int count_i = json.SizeOfArray("pins");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("pins[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("pin.user.changePermission");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("pin.user.changePermission[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("pin.user.unblockPermission");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("pin.user.unblockPermission[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("pin.admin.changePermission");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("pin.admin.changePermission[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("pin.role3.changePermission");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("pin.role3.changePermission[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("pin.role3.unblockPermission");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("pin.role3.unblockPermission[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("pin.role4.changePermission");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("pin.role4.changePermission[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("importSupport");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("importSupport[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("algorithms");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("algorithms[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("paddingSchemes");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("paddingSchemes[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("chainingModes");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("chainingModes[i]");
        i = i + 1;
    }

    // Delete the context when finished with the card.
    success = scmd.DeleteContext();
    if (success == false) {
        strOut.append(scmd.lastErrorText());
        strOut.append("\r\n");
    }



    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

    }

 

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