Guest User

Touchatag reader example

a guest
Jul 14th, 2010
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.34 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import javax.smartcardio.*;
  4. import java.util.List;
  5. import java.math.BigInteger;
  6.  
  7. public class Touchatag {
  8.  private CardTerminal terminal;
  9.   public Touchatag() throws CardException {
  10.       CardTerminals terminals = TerminalFactory.getDefault().terminals();
  11.       terminal = terminals.list().get(0);
  12.   }
  13.   public Touchatag(String readerName) {
  14.       CardTerminals terminals = TerminalFactory.getDefault().terminals();
  15.       terminal = terminals.getTerminal(readerName);
  16.   }
  17.   public byte[] getCardUID() throws CardException {
  18.       Card card = terminal.connect("*");
  19.       ResponseAPDU response = card.getBasicChannel().transmit(
  20.               new CommandAPDU(new byte[] { (byte) 0xFF, 0x00, 0x00, 0x00,
  21.                       0x04, (byte) 0xD4, 0x4A, 0x01, 0x00 }));
  22.       card.disconnect(true);
  23.       if (response.getSW1() == 0x90) {
  24.           byte[] data = response.getData();
  25.           data = Arrays.copyOfRange(data, 0x08, data.length);
  26.           return data;
  27.       }
  28.       return new byte[] {};
  29.   }
  30.   public static void main(String[] args) throws CardException {
  31.       Touchatag touchatag = new Touchatag();
  32.       byte[] bytes = touchatag.getCardUID();
  33.       System.out.println(String.format("%0" + (bytes.length << 1) + "X", new
  34. BigInteger(1, bytes)));
  35.   }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment