Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import javax.smartcardio.*;
- import java.util.List;
- import java.math.BigInteger;
- public class Touchatag {
- private CardTerminal terminal;
- public Touchatag() throws CardException {
- CardTerminals terminals = TerminalFactory.getDefault().terminals();
- terminal = terminals.list().get(0);
- }
- public Touchatag(String readerName) {
- CardTerminals terminals = TerminalFactory.getDefault().terminals();
- terminal = terminals.getTerminal(readerName);
- }
- public byte[] getCardUID() throws CardException {
- Card card = terminal.connect("*");
- ResponseAPDU response = card.getBasicChannel().transmit(
- new CommandAPDU(new byte[] { (byte) 0xFF, 0x00, 0x00, 0x00,
- 0x04, (byte) 0xD4, 0x4A, 0x01, 0x00 }));
- card.disconnect(true);
- if (response.getSW1() == 0x90) {
- byte[] data = response.getData();
- data = Arrays.copyOfRange(data, 0x08, data.length);
- return data;
- }
- return new byte[] {};
- }
- public static void main(String[] args) throws CardException {
- Touchatag touchatag = new Touchatag();
- byte[] bytes = touchatag.getCardUID();
- System.out.println(String.format("%0" + (bytes.length << 1) + "X", new
- BigInteger(1, bytes)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment