Package org.nfctools.mf.classic

Examples of org.nfctools.mf.classic.KeyValue


    MemoryLayout memoryLayout = readerWriter.getMemoryLayout();

    for (int sectorId = 0; sectorId < memoryLayout.getSectors(); sectorId++) {
      for (byte[] key : knownKeys) {
        try {
          MfClassicAccess access = new MfClassicAccess(new KeyValue(Key.A, key), sectorId, 0,
              memoryLayout.getBlocksPerSector(sectorId));
          MfBlock[] mfBlock = readerWriter.readBlock(access);
          for (int blockId = 0; blockId < mfBlock.length; blockId++) {
            System.out.println("S" + sectorId + "|B" + blockId + " Key: " + NfcUtils.convertBinToASCII(key)
                + " " + mfBlock[blockId]);
View Full Code Here


  private TrailerBlock readTrailerBlock(MfClassicReaderWriter readerWriter, int sectorId) throws IOException {
    MemoryLayout memoryLayout = readerWriter.getMemoryLayout();
    for (byte[] key : knownKeys) {
      try {
        MfClassicAccess access = new MfClassicAccess(new KeyValue(Key.A, key), sectorId,
            memoryLayout.getTrailerBlockNumberForSector(sectorId));
        MfBlock[] readBlock = readerWriter.readBlock(access);
        return (TrailerBlock)readBlock[0];
      }
      catch (MfLoginException e) {
View Full Code Here

  public void initMadTrailer(int madVersion) throws MfException, IOException {
    super.initMadTrailer(madVersion);
    trailerBlock = createTrailer(keyConfig.getWriteKeyValue());
    trailerBlock.setGeneralPurposeByte(MadConstants.GPB_MAD_2_TRAILER);

    MfClassicAccess accessTrailer = new MfClassicAccess(new KeyValue(keyConfig.getCreateKey(),
        keyConfig.getCreateKeyValue()), 16, memoryLayout.getTrailerBlockNumberForSector(16));
    readerWriter.writeBlock(accessTrailer, trailerBlock);
  }
View Full Code Here

      TrailerBlock trailerBlock = readTrailerBlock(readerWriter, sectorId);
      if (trailerBlock != null) {
        Key keyToWrite = trailerBlock.isKeyBReadable() ? Key.A : Key.B;
        for (byte[] key : knownKeys) {
          try {
            initTransportConfig(readerWriter, sectorId, new KeyValue(keyToWrite, key));
            for (int blockId = 0; blockId < memoryLayout.getBlocksPerSector(sectorId); blockId++) {
              if (!memoryLayout.isTrailerBlock(sectorId, blockId) && !(blockId == 0 && sectorId == 0)) {
                log.info("Cleaning S" + sectorId + "|B" + blockId);
                MfClassicAccess access = new MfClassicAccess(new KeyValue(Key.A,
                    MfConstants.TRANSPORT_KEY), sectorId, blockId);
                readerWriter.writeBlock(access, emptyDataBlock);
              }
            }
            log.info("Sector " + sectorId + " clear with key: " + NfcUtils.convertBinToASCII(key));
View Full Code Here

  }

  protected void readMad(byte[] madData, int sectorId, int firstBlockId, TrailerBlock trailerBlock)
      throws IOException {
    int blocksToRead = madData.length / MfConstants.BYTES_PER_BLOCK;
    MfClassicAccess access = new MfClassicAccess(new KeyValue(Key.A, trailerBlock.getKey(Key.A)), sectorId,
        firstBlockId, blocksToRead);
    MfBlock[] madBlocks = readerWriter.readBlock(access);
    for (int x = 0; x < blocksToRead; x++) {
      System.arraycopy(madBlocks[x].getData(), 0, madData, x * MfConstants.BYTES_PER_BLOCK,
          MfConstants.BYTES_PER_BLOCK);
 
View Full Code Here

      byte[] writeBuffer = new byte[MfConstants.BYTES_PER_BLOCK];
      System.arraycopy(madData, x * MfConstants.BYTES_PER_BLOCK, writeBuffer, 0, MfConstants.BYTES_PER_BLOCK);
      dataBlocks[x] = new DataBlock(writeBuffer);
    }

    MfClassicAccess access = new MfClassicAccess(new KeyValue(Key.B, trailerBlock.getKey(Key.B)), sectorId,
        firstBlockId);
    readerWriter.writeBlock(access, dataBlocks);
  }
View Full Code Here

    return crc.getCrc();
  }

  protected void writeTrailer(int trailerSectorId, TrailerBlock trailerBlock) throws IOException {
    MfClassicAccess accessTrailer = new MfClassicAccess(new KeyValue(keyConfig.getCreateKey(),
        keyConfig.getCreateKeyValue()), trailerSectorId,
        memoryLayout.getTrailerBlockNumberForSector(trailerSectorId));
    readerWriter.writeBlock(accessTrailer, trailerBlock);
  }
View Full Code Here

  }

  private void writeBlock(Key writeKey, byte[] writeKeyValue, TrailerBlock trailerBlock, int sectorId)
      throws IOException {

    MfClassicAccess access = new MfClassicAccess(new KeyValue(writeKey, writeKeyValue), sectorId,
        memoryLayout.getTrailerBlockNumberForSector(sectorId));

    readerWriter.writeBlock(access, trailerBlock);
  }
View Full Code Here

      int sectorId = mad.getSectorIdForSlot(slot);
      try {
        readBlockData(keyValue, baos, sectorId);
      }
      catch (MfLoginException e) {
        readBlockData(new KeyValue(keyValue.getKey(), MfConstants.TRANSPORT_KEY), baos, sectorId);
      }
    }
    return baos.toByteArray();
  }
View Full Code Here

    if (log.isDebugEnabled())
      log.debug("Length: " + tlvWrappedNdefData.length + " [" + NfcUtils.convertBinToASCII(tlvWrappedNdefData)
          + "]");

    application.write(new KeyValue(Key.B, writeKeyValue), tlvWrappedNdefData);
  }
View Full Code Here

TOP

Related Classes of org.nfctools.mf.classic.KeyValue

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.