Package javax.smartcardio

Examples of javax.smartcardio.CardChannel


  @Override
  public MfBlock[] readBlock(MfAccess mfAccess) throws IOException {

    AcsConnectionToken connectionToken = retrieveConnectionToken(mfAccess);
    CardChannel cardChannel = connectionToken.getCard().getBasicChannel();

    byte blockNumber;
    loginIntoSector(mfAccess, cardChannel);

    MfBlock[] returnBlocks = new Block[mfAccess.getBlocksToRead()];

    for (int currentBlock = 0; currentBlock < mfAccess.getBlocksToRead(); currentBlock++) {

      blockNumber = (byte)mfAccess.getCard().getBlockNumber(mfAccess.getSector(),
          mfAccess.getBlock() + currentBlock);

      CommandAPDU readBlock = new CommandAPDU(Apdu.CLS_PTS, Apdu.INS_READ_BINARY, 0x00, blockNumber, 16);
      ResponseAPDU readBlockResponse;
      try {
        readBlockResponse = cardChannel.transmit(readBlock);
        if (!ApduUtils.isSuccess(readBlockResponse)) {
          throw new MfException("Reading block failed. Sector: " + mfAccess.getSector() + ", Block: "
              + mfAccess.getBlock() + " Key: " + mfAccess.getKey().name() + ", Response: "
              + readBlockResponse);
        }
View Full Code Here


  }

  @Override
  public void writeBlock(MfAccess mfAccess, MfBlock... mfBlock) throws IOException {
    AcsConnectionToken connectionToken = retrieveConnectionToken(mfAccess);
    CardChannel cardChannel = connectionToken.getCard().getBasicChannel();

    loginIntoSector(mfAccess, cardChannel);

    for (int currentBlock = 0; currentBlock < mfBlock.length; currentBlock++) {
      int blockNumber = mfAccess.getCard().getBlockNumber(mfAccess.getSector(), mfAccess.getBlock())
          + currentBlock;

      if (mfAccess.getCard().isTrailerBlock(mfAccess.getSector(), mfAccess.getBlock() + currentBlock)) {
        if (!(mfBlock[currentBlock] instanceof TrailerBlock))
          throw new MfException("invalid block for trailer");
      }

      CommandAPDU writeBlock = new CommandAPDU(Apdu.CLS_PTS, Apdu.INS_UPDATE_BINARY, 0x00, blockNumber,
          mfBlock[currentBlock].getData());
      ResponseAPDU writeBlockResponse;
      try {
        writeBlockResponse = cardChannel.transmit(writeBlock);
        if (!ApduUtils.isSuccess(writeBlockResponse)) {
          throw new MfException("Writing block failed. Sector: " + mfAccess.getSector() + ", Block: "
              + mfAccess.getBlock() + " Key: " + mfAccess.getKey().name() + ", Response: "
              + writeBlockResponse);
        }
View Full Code Here

                System.out.println("card: " + card);
                System.out.println("proto: " + card.getProtocol());
                System.out.println("ATR-h: " + Converter.hexDump(card.getATR().getHistoricalBytes()));
                System.out.println("ATR: " + Converter.hexDump(card.getATR().getBytes()));
                CardChannel channel = card.getBasicChannel();
                System.out.println("Channel: " + channel.toString());
                System.out.println("Channel number: " + channel.getChannelNumber());

                 execTestScript(channel);

            } finally {
                card.disconnect(false);
View Full Code Here

TOP

Related Classes of javax.smartcardio.CardChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.