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 ( ) ;
}