本文整理汇总了Java中javax.smartcardio.CardException类的典型用法代码示例。如果您正苦于以下问题:Java CardException类的具体用法?Java CardException怎么用?Java CardException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CardException类属于javax.smartcardio包,在下文中一共展示了CardException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import javax.smartcardio.CardException; //导入依赖的package包/类
@Override
public ListenableFuture<ApduResponse> apply(byte[] in) {
// how to actually transmit to the card
// here we just use the normal transmit stuff
try {
ByteBuffer command = ByteBuffer.wrap(in);
ByteBuffer response = ByteBuffer.allocate(1024); // TODO is this reasonable?
int size = card.getBasicChannel().transmit(command, response);
byte[] out = new byte[size];
System.arraycopy(response.array(), 0,
out, 0, size);
return Futures.immediateFuture(new ApduResponse(out));
} catch (CardException e) {
throw new RuntimeException(e);
}
}
示例2: transmit
import javax.smartcardio.CardException; //导入依赖的package包/类
public ResponseAPDU transmit(CommandAPDU cmd)
throws CardException {
m_lastCommand = cmd;
if (m_bDebug == true) {
log(cmd);
}
long elapsed = -System.currentTimeMillis();
ResponseAPDU response = m_channel.transmit(cmd);
elapsed += System.currentTimeMillis();
m_lastTransmitTime = elapsed;
if (m_bDebug == true) {
log(response, m_lastTransmitTime);
}
return response;
}
示例3: transmit
import javax.smartcardio.CardException; //导入依赖的package包/类
private ResponseAPDU transmit(CardChannel channel, CommandAPDU cmd)
throws CardException {
log(cmd);
long elapsed = -System.currentTimeMillis();
ResponseAPDU response = channel.transmit(cmd);
elapsed += System.currentTimeMillis();
lastTransmitTime = elapsed;
log(response, elapsed);
return response;
}
示例4: create
import javax.smartcardio.CardException; //导入依赖的package包/类
public static SmartcardIoTransmitter create() throws CardException {
TerminalFactory tf = TerminalFactory.getDefault();
CardTerminal cardTerminal = null;
if (tf.terminals().list().size() == 1) {
cardTerminal = tf.terminals().list().get(0);
} else {
for (CardTerminal terminal : tf.terminals().list()) {
logger.info("Checking for card: {}", terminal.getName());
if (terminal.isCardPresent()) {
cardTerminal = terminal;
}
}
}
if (cardTerminal != null) {
cardTerminal.waitForCardPresent(0);
} else {
throw new RuntimeException("No card found!");
}
logger.info("Using -> " + cardTerminal.getName());
Card card = cardTerminal.connect("*");
return new SmartcardIoTransmitter(card);
}
示例5: sendCommandWithInitSequence
import javax.smartcardio.CardException; //导入依赖的package包/类
/**
* Sending command to the card.
* Enables to send init commands before the main one.
*
* @param cardMngr
* @param command
* @param initCommands
* @return
* @throws CardException
*/
public static ResponseAPDU sendCommandWithInitSequence(CardManager cardMngr, String command, ArrayList<String> initCommands) throws CardException {
if (initCommands != null) {
for (String cmd : initCommands) {
cardMngr.getChannel().transmit(new CommandAPDU(Util.hexStringToByteArray(cmd)));
}
}
final ResponseAPDU resp = cardMngr.getChannel().transmit(new CommandAPDU(Util.hexStringToByteArray(command)));
return resp;
}
示例6: waitForCard
import javax.smartcardio.CardException; //导入依赖的package包/类
private Card waitForCard(CardTerminals terminals)
throws CardException {
while (true) {
for (CardTerminal ct : terminals
.list(CardTerminals.State.CARD_INSERTION)) {
return ct.connect("*");
}
terminals.waitForChange();
}
}
示例7: transmit
import javax.smartcardio.CardException; //导入依赖的package包/类
@Override
public ResponseAPDU transmit(CommandAPDU apdu) throws CardException {
ResponseAPDU responseAPDU = null;
try {
responseAPDU = this.m_simulator.transmitCommand(apdu);
// TODO: Add delay corresponding to real cards
//int delay = OperationTimes.getCardOperationDelay(apdu);
//Thread.sleep(delay);
} catch (Exception ex) {
ex.printStackTrace();
}
return responseAPDU;
}
示例8: transmit
import javax.smartcardio.CardException; //导入依赖的package包/类
@Override
public ResponseAPDU transmit(CommandAPDU apdu) throws CardException {
ResponseAPDU responseAPDU = null;
try {
responseAPDU = this.m_simulator.transmitCommand(apdu);
} catch (Exception ex) {
ex.printStackTrace();
}
return responseAPDU;
}
示例9: helloTest
import javax.smartcardio.CardException; //导入依赖的package包/类
@Test
public void helloTest() throws CardException {
CommandAPDU c = new CommandAPDU(0x00, 0x40, 0x00, 0x00);
ResponseAPDU response = transmitCommand(c);
assertEquals(0x9000, response.getSW());
assertArrayEquals(hello, response.getData());
}
示例10: transmitCommand
import javax.smartcardio.CardException; //导入依赖的package包/类
public ResponseAPDU transmitCommand(CommandAPDU data) throws CardException {
if (System.getProperty("testMode") != null && System.getProperty("testMode").equals("smartcard")) {
return TestSuite.getCard().getBasicChannel().transmit(data);
} else {
return TestSuite.getSimulator().transmitCommand(data);
}
}
示例11: balanceOverflowTest
import javax.smartcardio.CardException; //导入依赖的package包/类
@Test
public void balanceOverflowTest() throws CardException {
sendCredit(MAX_CREDIT, 0x9000, MAX_CREDIT);
sendCredit(MAX_CREDIT, 0x9000, TestUtils.getByte(TestUtils.getInt(MAX_CREDIT) * 2));
sendCredit(new byte[]{0x00, 0x01}, ISO7816.SW_WRONG_DATA, new byte[]{});
assertArrayEquals(MAX_BALANCE, getBalance().getData());
}
示例12: debitTest
import javax.smartcardio.CardException; //导入依赖的package包/类
@Test
public void debitTest() throws CardException {
sendCredit(new byte[]{0x00, 0x05}, 0x9000, new byte[]{0x00, 0x05});
assertArrayEquals(new byte[]{0x00, 0x05}, getBalance().getData());
sendDebit(new byte[]{0x00, 0x05}, 0x9000, new byte[]{0x00, 0x00});
assertArrayEquals(new byte[]{0x00, 0x00}, getBalance().getData());
}
示例13: debitNegativeTest
import javax.smartcardio.CardException; //导入依赖的package包/类
@Test
public void debitNegativeTest() throws CardException {
sendCredit(new byte[]{0x00, 0x05}, 0x9000, new byte[]{0x00, 0x05});
assertArrayEquals(new byte[]{0x00, 0x05}, getBalance().getData());
sendDebit(new byte[]{0x00, 0x06}, ISO7816.SW_WRONG_DATA, new byte[]{});
assertArrayEquals(new byte[]{0x00, 0x05}, getBalance().getData());
}
示例14: multipleAddPasswordTest
import javax.smartcardio.CardException; //导入依赖的package包/类
@Test
public void multipleAddPasswordTest() throws CardException {
sendListId(new byte[]{}, 0x9000, new byte[]{});
sendAddPassword(DATA_ENTRY_VALID.getFullApdu(), 0x9000, new byte[]{});
sendAddPassword(DATA_ENTRY_VALID1.getFullApdu(), 0x9000, new byte[]{});
sendAddPassword(DATA_ENTRY_VALID2.getFullApdu(), 0x9000, new byte[]{});
sendAddPassword(DATA_ENTRY_VALID3.getFullApdu(), 0x9000, new byte[]{});
sendListId(new byte[]{}, 0x9000, TestUtils.concatByteArray(DATA_ENTRY_VALID3.getId(),
DATA_ENTRY_VALID2.getId(),
DATA_ENTRY_VALID1.getId(),
DATA_ENTRY_VALID.getId()));
}
示例15: invalidAddTagTest
import javax.smartcardio.CardException; //导入依赖的package包/类
@Test
public void invalidAddTagTest() throws CardException {
sendListId(new byte[]{}, 0x9000, new byte[]{});
sendAddPassword(DATA_ENTRY_INVALID_TAG1, ISO7816.SW_DATA_INVALID, new byte[]{});
sendAddPassword(DATA_ENTRY_INVALID_TAG2, ISO7816.SW_DATA_INVALID, new byte[]{});
sendAddPassword(DATA_ENTRY_INVALID_TAG3, ISO7816.SW_DATA_INVALID, new byte[]{});
sendListId(new byte[]{}, 0x9000, new byte[]{});
}