javax.smarcardio unknown exception 0x1f

I'm working on a card reader now. I want to take data from the card. I took uid. I want to take encrypted data. So I want to enter the secure mode and start session. I did something. I send a command apdu to start session but every time return unknown exception 0x1f here is the code.

    TerminalFactory factory = TerminalFactory.getDefault();

    List<CardTerminal> terminals = factory.terminals().list();

    terminal = terminals.get(0);
    card = terminal.connect("T=1");
    CardChannel channel = card.getBasicChannel();
    byte[] c1 = { (byte) 0x80, (byte) 0x72, (byte) 0x80, (byte) 0x00, (byte) 0x18, (byte) 0x5c, (byte) 0xc5,
            (byte) 0x0a, (byte) 0xa2, (byte) 0x5b, (byte) 0x38, (byte) 0x7f, (byte) 0x81, (byte) 0x3a, (byte) 0x3d,
            (byte) 0x1a, (byte) 0x88, (byte) 0x7d, (byte) 0x26, (byte) 0xfc, (byte) 0x2b, (byte) 0xa8, (byte) 0xa7,
            (byte) 0xdd, (byte) 0xdc, (byte) 0x71, (byte) 0xe0, (byte) 0xf3, (byte) 0xc6 };

    ResponseAPDU response = channel.transmit(new CommandAPDU(0xFF, 0x00,0x00,0x00,c1,5,24));

This code returns me 6a81( it means function not supported),

if I send directly start session command(84 72 00 00) this time returns unknown exception.

Please help me. You don't have to find the error in code. Tell me How Can I Start Session in a Smart Card. I use HID OMNİKEY 5021 CL.

Exception in thread "main" javax.smartcardio.CardException: sun.security.smartcardio.PCSCException: Unknown error 0x1f
at sun.security.smartcardio.ChannelImpl.doTransmit(ChannelImpl.java:219)
at sun.security.smartcardio.ChannelImpl.transmit(ChannelImpl.java:90)
at CardReader.GetUID.getUID(GetUID.java:48)
at CardReader.GetUID.main(GetUID.java:86)

Upvotes: 0

Views: 1255

Answers (2)

I found the problem. The problem is byte types .net and java. C# byte type between 0 and 255 but java byte type -127 and +128. So if I send a higher than 127 value to java, card interpret like minus value.

Upvotes: 0

vojta
vojta

Reputation: 5651

APDU you're sending is wrong, because you use CommandAPDU in an incorrect way.

new CommandAPDU(0xFF, 0x00,0x00,0x00,c1,5,24)

creates an APDU starting FF000000185CC50AA2... which is not what you (probably) want.

Try new CommandAPDU(0x84, 0x72,0x00,0x00,c1,5,24) instead.

See CommandAPDU javadoc and APDU format description.

Upvotes: 1

Related Questions