Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. FF000000 27 D48C 05 0400 123456 20 000000000000000000000000000000000000 00000000000000000000 00 00
  2.  
  3. //TgInitAsTarget
  4. byte[] bytes4 = { (byte) 0xD4,(byte) 0x8C,(byte) 0x05,(byte) 0x04,(byte) 0x00,
  5. (byte) 0x12,(byte) 0x34,(byte) 0x56,(byte) 0x20,
  6. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,
  7. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,
  8. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,
  9. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,
  10. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,
  11. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00 };
  12. CommandAPDU command4 = new CommandAPDU(0xFF,0x00,0x00,0x00, bytes4);
  13. ResponseAPDU response4 = channel.transmit(command4);
  14. System.out.println(bytesToHex(response4.getBytes()));
  15.  
  16. List<CardTerminal> terminals = null;
  17. TerminalFactory factory = TerminalFactory.getDefault();
  18. terminals = factory.terminals().list();
  19.  
  20. CardTerminal terminal = terminals.get(0);
  21. Card card = terminal.connect("*");
  22.  
  23. CardChannel channel = card.getBasicChannel();
  24.  
  25. //Read register
  26. byte[] bytes1 = {(byte) 0xD4, 0x06, 0x63, 0x05, 0x63, 0x0D, 0x63, 0x38 };
  27. CommandAPDU command1 = new CommandAPDU(0xFF,0x00,0x00,0x00, bytes1);
  28. ResponseAPDU response1 = channel.transmit(command1);
  29. System.out.println(bytesToHex(response1.getBytes()));
  30.  
  31. //Update registers
  32. int xx = 47;
  33. int yy = 00;
  34. int zz = 01;
  35. xx = xx | 0x004;
  36. yy = yy & 0x0EF;
  37. zz = zz & 0x0F7;
  38.  
  39. byte xxByte = toByte(hexStringToByteArray("0x"+Integer.toHexString(xx)));
  40. byte yyByte = toByte(hexStringToByteArray("0x0"+Integer.toHexString(yy)));
  41. byte zzByte = toByte(hexStringToByteArray("0x0"+Integer.toHexString(zz)));
  42.  
  43. //WriteRegister
  44. byte[] bytes2 = { (byte) 0xD4, 0x08, 0x63, 0x02, (byte) 0x80,
  45. 0x63, 0x03, (byte) 0x80, (byte) 0x63, (byte) 0x05,
  46. xxByte, 0x63, 0x0D,yyByte, 0x63, 0x38, zzByte};
  47. CommandAPDU command2 = new CommandAPDU(0xFF,0x00,0x00,0x00, bytes2);
  48. ResponseAPDU response2 = channel.transmit(command2);
  49. System.out.println(bytesToHex(response2.getBytes()));
  50.  
  51. //SetParameters
  52. byte[] bytes3 = {(byte) 0xD4,(byte) 0x12,(byte) 0x30};
  53. CommandAPDU command3 = new CommandAPDU(0xFF,0x00,0x00,0x00, bytes3);
  54. ResponseAPDU response3 = channel.transmit(command3);
  55. System.out.println(bytesToHex(response3.getBytes()));
  56.  
  57.  
  58. //TgInitAsTarget
  59. byte[] bytes4 = { (byte) 0xD4,(byte) 0x8C,(byte) 0x05,(byte) 0x04,(byte) 0x00,
  60. (byte) 0x12,(byte) 0x34,(byte) 0x56,(byte) 0x20,
  61. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,
  62. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,
  63. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,
  64. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,
  65. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,
  66. (byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00,(byte) 0x00 };
  67. CommandAPDU command4 = new CommandAPDU(0xFF,0x00,0x00,0x00, bytes4);
  68. ResponseAPDU response4 = channel.transmit(command4);
  69. System.out.println(bytesToHex(response4.getBytes()));
  70.  
  71. byte[] commandAPDU4 = {(byte)0xFF, 0x00, 0x00, 0x00 , 0x27 , (byte)0xD4, (byte)0x8C , 0x05 , 0x04, 0x00 , 0x12, 0x34, 0x56 , 0x20 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , 0x00};
  72. byte[] responseAPDU4 = card.transmitControlCommand(IOCTL_SMARTCARD_ACR122_ESCAPE_COMMAND, commandAPDU4 );
  73. System.out.println(bytesToHex(responseAPDU4) + "...");
  74.  
  75. //Response: D58D08E0809000...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement