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
(Delphi DLL) ScMinidriver - Get Smartcard PropertiesSee more ScMinidriver ExamplesGets information about the smart card currently inserted in the reader (or USB token).
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, ScMinidriver, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var scmd: HCkScMinidriver; readerName: PWideChar; success: Boolean; json: HCkJsonObject; strVal: PWideChar; bytesAvailable: Integer; containersAvailable: Integer; maxKeyContainers: Integer; capabilitiesFCertificateCompression: Boolean; capabilitiesFKeyGen: Boolean; keySizesMinimumBitlen: Integer; keySizesDefaultBitlen: Integer; keySizesMaximumBitlen: Integer; keySizesIncrementalBitlen: Integer; readOnly: Boolean; cacheMode: PWideChar; supportsWinX509Enrollment: Boolean; guid: PWideChar; serial: PWideChar; pinUserType: PWideChar; pinUserPurpose: PWideChar; pinUserCachePolicy: PWideChar; pinUserPolicyInfo: PWideChar; pinUserFlags: PWideChar; pinUserAcceptPlainTextPin: Boolean; pinUserGenerateSessionPin: Boolean; pinAdminType: PWideChar; pinAdminPurpose: PWideChar; pinAdminCachePolicy: PWideChar; pinAdminPolicyInfo: PWideChar; pinAdminFlags: PWideChar; pinRole3Type: PWideChar; pinRole3Purpose: PWideChar; pinRole3CachePolicy: PWideChar; pinRole3PolicyInfo: PWideChar; pinRole3Flags: PWideChar; pinRole3AcceptPlainTextPin: Boolean; pinRole3GenerateSessionPin: Boolean; pinRole4Type: PWideChar; pinRole4Purpose: PWideChar; pinRole4CachePolicy: PWideChar; pinRole4PolicyInfo: PWideChar; pinRole4Flags: PWideChar; pinRole4AcceptPlainTextPin: Boolean; pinRole4GenerateSessionPin: Boolean; i: Integer; count_i: Integer; begin // 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) then begin Memo1.Lines.Add(CkScMinidriver__lastErrorText(scmd)); Exit; end; json := CkJsonObject_Create(); CkJsonObject_putEmitCompact(json,False); success := CkScMinidriver_GetCardProperties(scmd,json); if (success = False) then begin Memo1.Lines.Add(CkScMinidriver__lastErrorText(scmd)); Exit; end; Memo1.Lines.Add(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 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 do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'pins[i]'); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(json,'pin.user.changePermission'); while i < count_i do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'pin.user.changePermission[i]'); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(json,'pin.user.unblockPermission'); while i < count_i do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'pin.user.unblockPermission[i]'); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(json,'pin.admin.changePermission'); while i < count_i do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'pin.admin.changePermission[i]'); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(json,'pin.role3.changePermission'); while i < count_i do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'pin.role3.changePermission[i]'); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(json,'pin.role3.unblockPermission'); while i < count_i do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'pin.role3.unblockPermission[i]'); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(json,'pin.role4.changePermission'); while i < count_i do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'pin.role4.changePermission[i]'); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(json,'importSupport'); while i < count_i do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'importSupport[i]'); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(json,'algorithms'); while i < count_i do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'algorithms[i]'); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(json,'paddingSchemes'); while i < count_i do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'paddingSchemes[i]'); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(json,'chainingModes'); while i < count_i do begin CkJsonObject_putI(json,i); strVal := CkJsonObject__stringOf(json,'chainingModes[i]'); i := i + 1; end; // Delete the context when finished with the card. success := CkScMinidriver_DeleteContext(scmd); if (success = False) then begin Memo1.Lines.Add(CkScMinidriver__lastErrorText(scmd)); end; CkScMinidriver_Dispose(scmd); CkJsonObject_Dispose(json); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.