WSCT Core
1.0.0
WSCT 核心项目的公共存储库。
自 2006 年以来,由 S.Vernois @ ENSICAEN / GREYC 在一些学生的帮助下开发,用于概念验证。
WSCT Core API 文档可从此网址获取:http://wsct.github.io/WSCT-Core
这是这个项目的主要API。它定义:
警告:仅此软件包无法访问具体的智能卡读卡器。为此使用下一个包。
该软件包无缝包装了本机 PC/SC 库。
支持的操作系统:
// Connect to PC/SC
var context = new CardContext ( ) ;
context . Establish ( ) ;
// Get installed readers
context . ListReaders ( " " ) ;
var allReaders = context . Readers ;
// Connect to an ISO7816-4 card in the last reader found
var channel = new CardChannel ( context , context . Readers . Last ( ) ) ;
channel . Connect ( ShareMode . Exclusive , Protocol . Any ) ;
// Build a SELECT command
var capdu = new SelectCommand (
SelectCommand . SelectionMode . SelectDFName ,
SelectCommand . FileOccurrence . FirstOrOnly ,
SelectCommand . FileControlInformation . ReturnFci ,
" A0 00 00 01 51 " . FromHexa ( )
) ;
// Send it in a CRP an get the response back
var crp = new CommandResponsePair ( capdu ) ;
crp . Transmit ( channel ) ;
var rapdu = crp . RApdu ;
// Unpower the card
channel . Disconnect ( Disposition . UnpowerCard ) ;
// Disconnect from PC/SC
context . Release ( ) ;
位于 WSCT.Core.Fluent.Helpers 命名空间中的一些扩展方法可用于简化原型设计(快速失败安全,同时编写更少的代码):
CardContext ? cardContext = null ;
CardChannel ? cardChannel = null ;
try
{
// Connect to PC/SC
cardContext = new new CardContext ( ) ;
cardContext
. Establish ( )
. ThrowIfNotSuccess ( ) ;
cardContext
. ListReaderGroups ( )
. ThrowIfNotSuccess ( ) ;
cardContext
. ListReaders ( cardContext . Groups [ 0 ] )
. ThrowIfNotSuccess ( ) ;
cardChannel = new CardChannel ( cardContext , cardContext . Readers [ 0 ] ) ;
new CommandAPDU ( " 00 A4 04 00 07 F0 57 53 43 54 2E 30 " )
. Transmit ( cardChannel )
. ThrowIfNotSuccess ( )
. ThrowIfSWNot9000 ( )
. If ( r => r . Sw1 == 0x61 , ( c , r ) => Console . WriteLine ( $" { r . Sw2 } bytes are waiting to be retrieved " ) ) ;
new CommandAPDU ( " 00 C0 00 00 08 " )
. Transmit ( cardChannel )
. ThrowIfNotSuccess ( )
. ThrowIfSWNot9000 ( ) ;
}
finally
{
cardChannel ?
. Disconnect ( Disposition . UnpowerCard ) ;
cardContext ?
. Release ( ) ;
}