authenticate Card - Java javax.smartcardio

Java examples for javax.smartcardio:CardChannel

Description

authenticate Card

Demo Code


//package com.java2s;

import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;

public class Main {
    public static void authenticate(Card c) throws CardException {
        byte cls = (byte) 0xFF;
        byte ins = (byte) 0x86;
        byte p1 = (byte) 0x00;
        byte p2 = (byte) 0x00;
        byte lc = (byte) 0x05;
        byte data = (byte) 0xFF;

        byte[] params = new byte[] { cls, ins, p1, p2, lc, 0x01, 0x00,
                0x04, 0x60, 0x00 };/* www.j a v  a2s.c om*/
        CardChannel channel = c.getBasicChannel();
        CommandAPDU command = new CommandAPDU(params);
        ResponseAPDU response = channel.transmit(command);
        validateResponse(response);
    }

    private static void validateResponse(ResponseAPDU response)
            throws CardException {
        if (response.getSW1() != 144) {
            throw new CardException(
                    "No fue posible cargar la autenticaci?n");
        }
    }
}

Related Tutorials