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
(Unicode C) ScMinidriver - Get Smartcard PropertiesSee more ScMinidriver ExamplesGets information about the smart card currently inserted in the reader (or USB token).
#include <C_CkScMinidriverW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkScMinidriverW scmd; const wchar_t *readerName; BOOL success; HCkJsonObjectW json; const wchar_t *strVal; int bytesAvailable; int containersAvailable; int maxKeyContainers; BOOL capabilitiesFCertificateCompression; BOOL capabilitiesFKeyGen; int keySizesMinimumBitlen; int keySizesDefaultBitlen; int keySizesMaximumBitlen; int keySizesIncrementalBitlen; BOOL readOnly; const wchar_t *cacheMode; BOOL supportsWinX509Enrollment; const wchar_t *guid; const wchar_t *serial; const wchar_t *pinUserType; const wchar_t *pinUserPurpose; const wchar_t *pinUserCachePolicy; const wchar_t *pinUserPolicyInfo; const wchar_t *pinUserFlags; BOOL pinUserAcceptPlainTextPin; BOOL pinUserGenerateSessionPin; const wchar_t *pinAdminType; const wchar_t *pinAdminPurpose; const wchar_t *pinAdminCachePolicy; const wchar_t *pinAdminPolicyInfo; const wchar_t *pinAdminFlags; const wchar_t *pinRole3Type; const wchar_t *pinRole3Purpose; const wchar_t *pinRole3CachePolicy; const wchar_t *pinRole3PolicyInfo; const wchar_t *pinRole3Flags; BOOL pinRole3AcceptPlainTextPin; BOOL pinRole3GenerateSessionPin; const wchar_t *pinRole4Type; const wchar_t *pinRole4Purpose; const wchar_t *pinRole4CachePolicy; const wchar_t *pinRole4PolicyInfo; const wchar_t *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 = CkScMinidriverW_Create(); // Reader names (smart card readers or USB tokens) can be discovered // via PCSC List Readers or PCSC Find Smart Cards readerName = L"Alcor Micro USB Smart Card Reader 0"; success = CkScMinidriverW_AcquireContext(scmd,readerName); if (success == FALSE) { wprintf(L"%s\n",CkScMinidriverW_lastErrorText(scmd)); CkScMinidriverW_Dispose(scmd); return; } json = CkJsonObjectW_Create(); CkJsonObjectW_putEmitCompact(json,FALSE); success = CkScMinidriverW_GetCardProperties(scmd,json); if (success == FALSE) { wprintf(L"%s\n",CkScMinidriverW_lastErrorText(scmd)); CkScMinidriverW_Dispose(scmd); CkJsonObjectW_Dispose(json); return; } wprintf(L"%s\n",CkJsonObjectW_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 = CkJsonObjectW_IntOf(json,L"bytesAvailable"); containersAvailable = CkJsonObjectW_IntOf(json,L"containersAvailable"); maxKeyContainers = CkJsonObjectW_IntOf(json,L"maxKeyContainers"); capabilitiesFCertificateCompression = CkJsonObjectW_BoolOf(json,L"capabilities.fCertificateCompression"); capabilitiesFKeyGen = CkJsonObjectW_BoolOf(json,L"capabilities.fKeyGen"); keySizesMinimumBitlen = CkJsonObjectW_IntOf(json,L"keySizes.minimumBitlen"); keySizesDefaultBitlen = CkJsonObjectW_IntOf(json,L"keySizes.defaultBitlen"); keySizesMaximumBitlen = CkJsonObjectW_IntOf(json,L"keySizes.maximumBitlen"); keySizesIncrementalBitlen = CkJsonObjectW_IntOf(json,L"keySizes.incrementalBitlen"); readOnly = CkJsonObjectW_BoolOf(json,L"readOnly"); cacheMode = CkJsonObjectW_stringOf(json,L"cacheMode"); supportsWinX509Enrollment = CkJsonObjectW_BoolOf(json,L"supportsWinX509Enrollment"); guid = CkJsonObjectW_stringOf(json,L"guid"); serial = CkJsonObjectW_stringOf(json,L"serial"); pinUserType = CkJsonObjectW_stringOf(json,L"pin.user.type"); pinUserPurpose = CkJsonObjectW_stringOf(json,L"pin.user.purpose"); pinUserCachePolicy = CkJsonObjectW_stringOf(json,L"pin.user.cachePolicy"); pinUserPolicyInfo = CkJsonObjectW_stringOf(json,L"pin.user.policyInfo"); pinUserFlags = CkJsonObjectW_stringOf(json,L"pin.user.flags"); pinUserAcceptPlainTextPin = CkJsonObjectW_BoolOf(json,L"pin.user.acceptPlainTextPin"); pinUserGenerateSessionPin = CkJsonObjectW_BoolOf(json,L"pin.user.generateSessionPin"); pinAdminType = CkJsonObjectW_stringOf(json,L"pin.admin.type"); pinAdminPurpose = CkJsonObjectW_stringOf(json,L"pin.admin.purpose"); pinAdminCachePolicy = CkJsonObjectW_stringOf(json,L"pin.admin.cachePolicy"); pinAdminPolicyInfo = CkJsonObjectW_stringOf(json,L"pin.admin.policyInfo"); pinAdminFlags = CkJsonObjectW_stringOf(json,L"pin.admin.flags"); pinRole3Type = CkJsonObjectW_stringOf(json,L"pin.role3.type"); pinRole3Purpose = CkJsonObjectW_stringOf(json,L"pin.role3.purpose"); pinRole3CachePolicy = CkJsonObjectW_stringOf(json,L"pin.role3.cachePolicy"); pinRole3PolicyInfo = CkJsonObjectW_stringOf(json,L"pin.role3.policyInfo"); pinRole3Flags = CkJsonObjectW_stringOf(json,L"pin.role3.flags"); pinRole3AcceptPlainTextPin = CkJsonObjectW_BoolOf(json,L"pin.role3.acceptPlainTextPin"); pinRole3GenerateSessionPin = CkJsonObjectW_BoolOf(json,L"pin.role3.generateSessionPin"); pinRole4Type = CkJsonObjectW_stringOf(json,L"pin.role4.type"); pinRole4Purpose = CkJsonObjectW_stringOf(json,L"pin.role4.purpose"); pinRole4CachePolicy = CkJsonObjectW_stringOf(json,L"pin.role4.cachePolicy"); pinRole4PolicyInfo = CkJsonObjectW_stringOf(json,L"pin.role4.policyInfo"); pinRole4Flags = CkJsonObjectW_stringOf(json,L"pin.role4.flags"); pinRole4AcceptPlainTextPin = CkJsonObjectW_BoolOf(json,L"pin.role4.acceptPlainTextPin"); pinRole4GenerateSessionPin = CkJsonObjectW_BoolOf(json,L"pin.role4.generateSessionPin"); i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"pins"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"pins[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"pin.user.changePermission"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"pin.user.changePermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"pin.user.unblockPermission"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"pin.user.unblockPermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"pin.admin.changePermission"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"pin.admin.changePermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"pin.role3.changePermission"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"pin.role3.changePermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"pin.role3.unblockPermission"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"pin.role3.unblockPermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"pin.role4.changePermission"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"pin.role4.changePermission[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"importSupport"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"importSupport[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"algorithms"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"algorithms[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"paddingSchemes"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"paddingSchemes[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"chainingModes"); while (i < count_i) { CkJsonObjectW_putI(json,i); strVal = CkJsonObjectW_stringOf(json,L"chainingModes[i]"); i = i + 1; } // Delete the context when finished with the card. success = CkScMinidriverW_DeleteContext(scmd); if (success == FALSE) { wprintf(L"%s\n",CkScMinidriverW_lastErrorText(scmd)); } CkScMinidriverW_Dispose(scmd); CkJsonObjectW_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.