PCSC Sample in Swift
PCSC Sample in Swift
更多 下一个博客» 创建博客 登录
To continue the list of PC/SC wrappers initiated in 2010 with "PC/SC sample in different languages" I now Follow
present a sample in Swift using the Apple Crypto Token Kit API.
https://ludovicrousseau.blogspot.jp/2015/09/pcscsampleinswift.html 1/3
12/14/2017 Ludovic Rousseau's blog: PCSC sample in Swift
if (error != nil) Ludovic Rousseau b…
{ Follow
print("sendIns error:", error!)
}
else
{
print("Response:", data!, String(sw, radix: 16))
let newString = NSString(bytes: data!.bytes, length: d
ata!.length, encoding: NSASCIIStringEncoding)
print(newString!)
}
})
}
}) 336 have us in View
} circles all
else
{
print("Session error:", error)
}
})
}
else
{
print("No card found")
}
})
Output
slotName: Gemalto PC Twin Reader
Response: <> 9000
Response: <48656c6c 6f20776f 726c6421> 9000
Hello world!
Comments
See the previous article "PCSC sample in ObjectiveC" for comments about the Crypto Token Kit API.
Swift may be easier to learn and use than ObjectiveC. Using the Crypto Token Kit API is not different if you
use ObjectiveC or Swift.
It looks like I am the first to provide a public code sample using the Crypto Token Kit API in Swift. Great! I
hope that is a good Swift sample, I am not a Swift expert.
Conclusion
As I wrote in "PCSC framework will stay in Mac OS X 10.11 El Capitan" the PC/SC API is not available from
Swift. So the only option (for now) to use a smart card from Swift is to use the Crypto Token Kit API.
I then discovered that if the card returns an "error" code then the sendIns method returns an error in the error
parameter. Here is the execution output of the program with a card that does not contain the applet:
The card returns 0x6A82 (Wrong parameter(s) P1P2, File not found) in SW (Status Word).
It may be difficult to differentiate errors at the card/reader communication level from "errors" returned by the
card. A SW different from 0x9000 may be completely valid and expected by the application in some cases.
https://ludovicrousseau.blogspot.jp/2015/09/pcscsampleinswift.html 2/3
12/14/2017 Ludovic Rousseau's blog: PCSC sample in Swift
Bitcoin
License: byncsa
This blog by Ludovic Rousseau is licensed under a Creative Commons AttributionNonCommercialShareAlike 3.0 Unported License.
https://ludovicrousseau.blogspot.jp/2015/09/pcscsampleinswift.html 3/3