Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Guides   Examples
New in version: 7.5   8.0   8.1   8.2   8.3   8.4   8.5   9.0   9.1   9.2    Statistic  

SmartCard.ReadFile

Read file from smart card with APDU protocol.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
SmartCard 8.5 Yes Yes Yes No No
MBS( "SmartCard.ReadFile"; SmartCardContext; FileID; ResultType )   More

Parameters

Parameter Description Example value
SmartCardContext The smartcard context reference number. $SmartCardContext
FileID The fileID of the file to retrieve.
Given as hex string.
"2F07"
ResultType How to return data.
Can be JPEG, Hex or Base64.
"Hex"

Result

Returns data or error.

Description

Read file from smart card with APDU protocol.
Returns data in desired encoding or error message.
The first two bytes (4 Hex characters) are status code.
For JPEG we remove status code to return only image.

Examples

Read file from smartcard with APDU protocol:

Set Variable [ $result ; Value: MBS( "SmartCard.ReadFile"; $$SmartCard; Card::FileID) ]
If [ MBS("IsError") ]
    Set Field [ Card::Status ; $result ]
    Show Custom Dialog [ "Error" ; $result ]
Else
    Set Field [ Card::FileData ; Middle ( $result ; 5; Length($result) ) ]
    Set Field [ Card::Status ; "OK " & Left ( $result ; 4 ) ]
    #
    Perform Script [ Specified: From list ; “Split” ; Parameter: ]
End If

Query name from Swiss health card:

# Initialize smart card:
Set Variable [ $$SmartCard ; Value: MBS( "SmartCard.Init" ) ]
If [ MBS("IsError") ]
    Show Custom Dialog [ "Failed to initialize SmartCard" ; $$SmartCard ]
    Exit Script [ Text Result: ]
End If
#
# Connect to a reader
Set Variable [ $reader ; Value: "Identiv SCR3310 uTrust 2700 R" ]
Set Variable [ $r ; Value: MBS( "SmartCard.Connect"; $$SmartCard; $Reader; "Shared"; "any" ) ]
If [ MBS("IsError") ]
    Show Custom Dialog [ "Connect failed" ; $r ]
    Exit Script [ Text Result: ]
End If
#
# Read file from smartcard with APDU protocol.
#
# Read record with name
Set Variable [ $result ; Value: MBS( "SmartCard.ReadFile"; $$SmartCard; "2F06") ]
If [ MBS("IsError") ]
    Set Field [ Card::Status ; $result ]
    Show Custom Dialog [ "Error" ; $result ]
    Exit Script [ Text Result: ]
End If
# Pick result
Set Variable [ $filedata ; Value: Middle ( $result ; 5; Length($result) ) ]
#
# Split in values
Set Variable [ $json ; Value: MBS("SmartCard.SplitValues"; $FileData) ]
# Get item 128, which is full name
Set Variable [ $name ; Value: JSONGetElement ( $json ; "128" ) ]
Set Variable [ $NameList ; Value: Substitute($name; ", "; ¶) ]
Set Variable [ $LastName ; Value: GetValue($nameList; 1) ]
Set Variable [ $FirstName ; Value: GetValue($nameList; 2) ]
#
Show Custom Dialog [ "Name" ; $FirstName & " " & $LastName ]
Set Variable [ $r ; Value: MBS( "SmartCard.Disconnect"; $$SmartCard; "Eject") ]

See also

Example Databases

Blog Entries

Created 19th October 2018, last changed 8th March 2019


SmartCard.ReadCertificate   -   SmartCard.Reconnect

Feedback: Report problem or ask question.




Links
MBS FileMaker Plugins