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
(Java) ScMinidriver - Get Smartcard PropertiesSee more ScMinidriver ExamplesGets information about the smart card currently inserted in the reader (or USB token).
import com.chilkatsoft.*; public class ChilkatExample { static { try { System.loadLibrary("chilkat"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load.\n" + e); System.exit(1); } } public static void main(String argv[]) { // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkScMinidriver scmd = new CkScMinidriver(); // Reader names (smart card readers or USB tokens) can be discovered // via PCSC List Readers or PCSC Find Smart Cards String readerName = "Alcor Micro USB Smart Card Reader 0"; boolean success = scmd.AcquireContext(readerName); if (success == false) { System.out.println(scmd.lastErrorText()); return; } CkJsonObject json = new CkJsonObject(); json.put_EmitCompact(false); success = scmd.GetCardProperties(json); if (success == false) { System.out.println(scmd.lastErrorText()); return; } System.out.println(json.emit()); // 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 String strVal; int bytesAvailable = json.IntOf("bytesAvailable"); int containersAvailable = json.IntOf("containersAvailable"); int maxKeyContainers = json.IntOf("maxKeyContainers"); boolean capabilitiesFCertificateCompression = json.BoolOf("capabilities.fCertificateCompression"); boolean 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"); boolean readOnly = json.BoolOf("readOnly"); String cacheMode = json.stringOf("cacheMode"); boolean supportsWinX509Enrollment = json.BoolOf("supportsWinX509Enrollment"); String guid = json.stringOf("guid"); String serial = json.stringOf("serial"); String pinUserType = json.stringOf("pin.user.type"); String pinUserPurpose = json.stringOf("pin.user.purpose"); String pinUserCachePolicy = json.stringOf("pin.user.cachePolicy"); String pinUserPolicyInfo = json.stringOf("pin.user.policyInfo"); String pinUserFlags = json.stringOf("pin.user.flags"); boolean pinUserAcceptPlainTextPin = json.BoolOf("pin.user.acceptPlainTextPin"); boolean pinUserGenerateSessionPin = json.BoolOf("pin.user.generateSessionPin"); String pinAdminType = json.stringOf("pin.admin.type"); String pinAdminPurpose = json.stringOf("pin.admin.purpose"); String pinAdminCachePolicy = json.stringOf("pin.admin.cachePolicy"); String pinAdminPolicyInfo = json.stringOf("pin.admin.policyInfo"); String pinAdminFlags = json.stringOf("pin.admin.flags"); String pinRole3Type = json.stringOf("pin.role3.type"); String pinRole3Purpose = json.stringOf("pin.role3.purpose"); String pinRole3CachePolicy = json.stringOf("pin.role3.cachePolicy"); String pinRole3PolicyInfo = json.stringOf("pin.role3.policyInfo"); String pinRole3Flags = json.stringOf("pin.role3.flags"); boolean pinRole3AcceptPlainTextPin = json.BoolOf("pin.role3.acceptPlainTextPin"); boolean pinRole3GenerateSessionPin = json.BoolOf("pin.role3.generateSessionPin"); String pinRole4Type = json.stringOf("pin.role4.type"); String pinRole4Purpose = json.stringOf("pin.role4.purpose"); String pinRole4CachePolicy = json.stringOf("pin.role4.cachePolicy"); String pinRole4PolicyInfo = json.stringOf("pin.role4.policyInfo"); String pinRole4Flags = json.stringOf("pin.role4.flags"); boolean pinRole4AcceptPlainTextPin = json.BoolOf("pin.role4.acceptPlainTextPin"); boolean 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) { System.out.println(scmd.lastErrorText()); } } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.