WSCT Core
1.0.0
Repositório público para o projeto WSCT Core.
Desenvolvido por S.Vernois@ENSICAEN/GREYC desde 2006 com ajuda de alguns alunos para prova de conceitos.
A documentação da API WSCT Core está disponível neste URL: http://wsct.github.io/WSCT-Core
Esta é a API principal deste projeto. Ele define:
Atenção: este pacote por si só não dá acesso a um leitor de cartão inteligente concreto. Use o próximo pacote para isso.
Este pacote envolve perfeitamente bibliotecas nativas de PC/SC.
SO suportado:
// 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 ( ) ;
Alguns métodos de extensão localizados no namespace WSCT.Core.Fluent.Helpers podem ser usados para facilitar a prototipagem (fail fast fail safe ao escrever menos código):
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 ( ) ;
}