Search in sources :

Example 1 with SelectDfByNameApduCommand

use of es.gob.jmulticard.apdu.iso7816four.SelectDfByNameApduCommand in project jmulticard by ctt-gob-es.

the class TestApdus method testSelectDfByName.

/**
 * Prueba de APDU de selección de DF por nombre.
 * @throws Exception En cualquier error.
 */
@SuppressWarnings("static-method")
@Test
public void testSelectDfByName() throws Exception {
    final byte[] dfName = new byte[] { (byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x63, (byte) 0x50, (byte) 0x4B, (byte) 0x43, (byte) 0x53, (byte) 0x2D, (byte) 0x31, (byte) 0x35 };
    final CommandApdu selectDfByName = new SelectDfByNameApduCommand((byte) 0x00, dfName);
    System.out.println(new String(dfName, StandardCharsets.UTF_8));
    System.out.println(HexUtils.hexify(selectDfByName.getBytes(), true));
}
Also used : SelectDfByNameApduCommand(es.gob.jmulticard.apdu.iso7816four.SelectDfByNameApduCommand) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) Test(org.junit.Test)

Example 2 with SelectDfByNameApduCommand

use of es.gob.jmulticard.apdu.iso7816four.SelectDfByNameApduCommand in project jmulticard by ctt-gob-es.

the class Iso7816FourCard method selectFileByName.

/**
 * Selecciona un fichero por nombre.
 * @param name Nombre del fichero en hexadecimal
 * @throws FileNotFoundException Si el fichero no existe
 * @throws ApduConnectionException Si ocurre algún problema durante la selección
 * @throws Iso7816FourCardException Si el fichero no se puede seleccionar por cualquier otra causa
 */
public void selectFileByName(final byte[] name) throws ApduConnectionException, FileNotFoundException, Iso7816FourCardException {
    final CommandApdu selectCommand = new SelectDfByNameApduCommand(getCla(), name);
    final ResponseApdu response = sendArbitraryApdu(selectCommand);
    if (response.isOk()) {
        return;
    }
    final StatusWord sw = response.getStatusWord();
    if (sw.equals(new StatusWord((byte) 0x6A, (byte) 0x82))) {
        throw new FileNotFoundException(name);
    }
    throw new Iso7816FourCardException(sw, selectCommand);
}
Also used : SelectDfByNameApduCommand(es.gob.jmulticard.apdu.iso7816four.SelectDfByNameApduCommand) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) StatusWord(es.gob.jmulticard.apdu.StatusWord) ResponseApdu(es.gob.jmulticard.apdu.ResponseApdu)

Aggregations

CommandApdu (es.gob.jmulticard.apdu.CommandApdu)2 SelectDfByNameApduCommand (es.gob.jmulticard.apdu.iso7816four.SelectDfByNameApduCommand)2 ResponseApdu (es.gob.jmulticard.apdu.ResponseApdu)1 StatusWord (es.gob.jmulticard.apdu.StatusWord)1 Test (org.junit.Test)1