Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C) ScMinidriver - Get Smartcard PropertiesSee more ScMinidriver ExamplesGets information about the smart card currently inserted in the reader (or USB token).
#include <C_CkScMinidriver.h> #include <C_CkJsonObject.h> void ChilkatSample(void) { HCkScMinidriver scmd; const char *readerName; BOOL success; HCkJsonObject json; const char *strVal; int bytesAvailable; int containersAvailable; int maxKeyContainers; BOOL capabilitiesFCertificateCompression; BOOL capabilitiesFKeyGen; int keySizesMinimumBitlen; int keySizesDefaultBitlen; int keySizesMaximumBitlen; int keySizesIncrementalBitlen; BOOL readOnly; const char *cacheMode; BOOL supportsWinX509Enrollment; const char *guid; const char *serial; const char *pinUserType; const char *pinUserPurpose; const char *pinUserCachePolicy; const char *pinUserPolicyInfo; const char *pinUserFlags; BOOL pinUserAcceptPlainTextPin; BOOL pinUserGenerateSessionPin; const char *pinAdminType; const char *pinAdminPurpose; const char *pinAdminCachePolicy; const char *pinAdminPolicyInfo; const char *pinAdminFlags; const char *pinRole3Type; const char *pinRole3Purpose; const char *pinRole3CachePolicy; const char *pinRole3PolicyInfo; const char *pinRole3Flags; BOOL pinRole3AcceptPlainTextPin; BOOL pinRole3GenerateSessionPin; const char *pinRole4Type; const char *pinRole4Purpose; const char *pinRole4CachePolicy; const char *pinRole4PolicyInfo; const char *pinRole4Flags; BOOL pinRole4AcceptPlainTextPin; BOOL pinRole4GenerateSessionPin; int i; int count_i; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. scmd = CkScMinidriver_Create(); // Reader names (smart card readers or USB tokens) can be discovered // via PCSC List Readers or PCSC Find Smart Cards readerName = "Alcor Micro USB Smart Card Reader 0"; success = CkScMinidriver_AcquireContext(scmd,readerName); if (success == FALSE) { printf("%s\n",CkScMinidriver_lastErrorText(scmd)); CkScMinidriver_Dispose(scmd); return; } json = CkJsonObject_Create(); CkJsonObject_putEmitCompact(json,FALSE); success = CkScMinidriver_GetCardProperties(scmd,json); if (success == FALSE) { printf("%s\n",CkScMinidriver_lastErrorText(scmd)); CkScMinidriver_Dispose(scmd); CkJsonObject_Dispose(json); return; } printf("%s\n",CkJsonObject_emit(json)); // 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. bytesAvailable = CkJsonObject_IntOf(json,"bytesAvailable"); containersAvailable = CkJsonObject_IntOf(json,"containersAvailable"); maxKeyContainers = CkJsonObject_IntOf(json,"maxKeyContainers"); capabilitiesFCertificateCompression = CkJsonObject_BoolOf(json,"capabilities.fCertificateCompression"); capabilitiesFKeyGen = CkJsonObject_BoolOf(json,"capabilities.fKeyGen"); keySizesMinimumBitlen = CkJsonObject_IntOf(json,"keySizes.minimumBitlen"); keySizesDefaultBitlen = CkJsonObject_IntOf(json,"keySizes.defaultBitlen"); keySizesMaximumBitlen = CkJsonObject_IntOf(json,"keySizes.maximumBitlen"); keySizesIncrementalBitlen = CkJsonObject_IntOf(json,"keySizes.incrementalBitlen"); readOnly = CkJsonObject_BoolOf(json,"readOnly"); cacheMode = CkJsonObject_stringOf(json,"cacheMode"); supportsWinX509Enrollment = CkJsonObject_BoolOf(json,"supportsWinX509Enrollment"); guid = CkJsonObject_stringOf(json,"guid"); serial = CkJsonObject_stringOf(json,"serial"); pinUserType = CkJsonObject_stringOf(json,"pin.user.type"); pinUserPurpose = CkJsonObject_stringOf(json,"pin.user.purpose"); pinUserCachePolicy = CkJsonObject_stringOf(json,"pin.user.cachePolicy"); pinUserPolicyInfo = CkJsonObject_stringOf(json,"pin.user.policyInfo"); pinUserFlags = CkJsonObject_stringOf(json,"pin.user.flags"); pinUserAcceptPlainTextPin = CkJsonObject_BoolOf(json,"pin.user.acceptPlainTextPin"); pinUserGenerateSessionPin = CkJsonObject_BoolOf(json,"pin.user.generateSessionPin"); pinAdminType = CkJsonObject_stringOf(json,"pin.admin.type"); pinAdminPurpose = CkJsonObject_stringOf(json,"pin.admin.purpose"); pinAdminCachePolicy = CkJsonObject_stringOf(json,"pin.admin.cachePolicy"); pinAdminPolicyInfo = CkJsonObject_stringOf(json,"pin.admin.policyInfo"); pinAdminFlags = CkJsonObject_stringOf(json,"pin.admin.flags"); pinRole3Type = CkJsonObject_stringOf(json,"pin.role3.type"); pinRole3Purpose = CkJsonObject_stringOf(json,"pin.role3.purpose"); pinRole3CachePolicy = CkJsonObject_stringOf(json,"pin.role3.cachePolicy"); pinRole3PolicyInfo = CkJsonObject_stringOf(json,"pin.role3.policyInfo"); pinRole3Flags = CkJsonObject_stringOf(json,"pin.role3.flags"); pinRole3AcceptPlainTextPin = CkJsonObject_BoolOf(json,"pin.role3.acceptPlainTextPin"); pinRole3GenerateSessionPin = CkJsonObject_BoolOf(json,"pin.role3.generateSessionPin"); pinRole4Type = CkJsonObject_stringOf(json,"pin.role4.type"); pinRole4Purpose = CkJsonObject_stringOf(json,"pin.role4.purpose"); pinRole4CachePolicy = CkJsonObject_stringOf(json,"pin.role4.cachePolicy"); pinRole4PolicyInfo = CkJsonObject_stringOf(json,"pin.role4.policyInfo"); pinRole4Flags = CkJsonObject_stringOf(json,"pin.role4.flags"); pinRole4AcceptPlainTextPin = CkJsonObject_BoolOf(json,"pin.role4.acceptPlainTextPin"); pinRole4GenerateSessionPin = CkJsonObject_BoolOf(json,"pin.role4.generateSessionPin"); i = 0; count_i = CkJsonObject_SizeOfArray(json,"pins"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"pins[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(json,"pin.user.changePermission"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"pin.user.changePermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(json,"pin.user.unblockPermission"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"pin.user.unblockPermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(json,"pin.admin.changePermission"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"pin.admin.changePermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(json,"pin.role3.changePermission"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"pin.role3.changePermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(json,"pin.role3.unblockPermission"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"pin.role3.unblockPermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(json,"pin.role4.changePermission"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"pin.role4.changePermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(json,"importSupport"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"importSupport[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(json,"algorithms"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"algorithms[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(json,"paddingSchemes"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"paddingSchemes[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(json,"chainingModes"); while (i < count_i) { CkJsonObject_putI(json,i); strVal = CkJsonObject_stringOf(json,"chainingModes[i]"); i = i + 1; } // Delete the context when finished with the card. success = CkScMinidriver_DeleteContext(scmd); if (success == FALSE) { printf("%s\n",CkScMinidriver_lastErrorText(scmd)); } CkScMinidriver_Dispose(scmd); CkJsonObject_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.