Search in sources :

Example 6 with JseCryptoHelper

use of es.gob.jmulticard.JseCryptoHelper in project jmulticard by ctt-gob-es.

the class TestApduEncrypter method testPartialEncryptionAes.

/**
 * Prueba de cifrado AES del cuerpo de una APDU.
 * @throws Exception En cualquier error.
 */
@Test
public void testPartialEncryptionAes() throws Exception {
    this.paddingLength = 16;
    final CommandApdu apdu = new CommandApdu((byte) 0x00, (byte) 0xa4, (byte) 0x04, (byte) 0x00, new byte[] { (byte) 0x4d, (byte) 0x61, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x2e, (byte) 0x46, (byte) 0x69, (byte) 0x6c, (byte) 0x65 }, null);
    Assert.assertEquals(// $NON-NLS-1$
    "00a404000b4d61737465722e46696c65", HexUtils.hexify(apdu.getBytes(), false).toLowerCase());
    final byte[] paddedData = addPadding7816(apdu.getData(), this.paddingLength);
    Assert.assertEquals(// $NON-NLS-1$
    "4d61737465722e46696c658000000000", HexUtils.hexify(paddedData, false).toLowerCase());
    final byte[] encryptedApdu = encryptData(paddedData, KENC2, SSC2, new JseCryptoHelper());
    Assert.assertEquals(// $NON-NLS-1$
    "f5124ee2f53962e86e66a6d234827f0f", HexUtils.hexify(encryptedApdu, false).toLowerCase());
}
Also used : CommandApdu(es.gob.jmulticard.apdu.CommandApdu) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) Test(org.junit.Test)

Example 7 with JseCryptoHelper

use of es.gob.jmulticard.JseCryptoHelper in project jmulticard by ctt-gob-es.

the class TestApduEncrypter method testEncryptionDes.

/**
 * Prueba de cifrado 3DES de APDU.
 * @throws Exception En cualquier error.
 */
@SuppressWarnings("static-method")
@Test
public void testEncryptionDes() throws Exception {
    final ApduEncrypter apduEncrypterDes = new ApduEncrypterDes();
    final CipheredApdu a = apduEncrypterDes.protectAPDU(new CommandApdu((byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, new byte[] { (byte) 0x4d, (byte) 0x61, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x2e, (byte) 0x46, (byte) 0x69, (byte) 0x6c, (byte) 0x65 }, null), KENC, KMAC, SSC_SIMPLE, new JseCryptoHelper());
    Assert.assertEquals(// $NON-NLS-1$
    "0ca40400198711013e9ac315a8e855dd3722f291078ac2bd8e04b6f56963", HexUtils.hexify(a.getBytes(), false).toLowerCase());
}
Also used : ApduEncrypterDes(es.gob.jmulticard.apdu.connection.ApduEncrypterDes) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) ApduEncrypter(es.gob.jmulticard.apdu.connection.ApduEncrypter) CipheredApdu(es.gob.jmulticard.apdu.connection.CipheredApdu) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) Test(org.junit.Test)

Example 8 with JseCryptoHelper

use of es.gob.jmulticard.JseCryptoHelper in project jmulticard by ctt-gob-es.

the class DnieNFC method getPaceConnection.

private static ApduConnection getPaceConnection(final ApduConnection con) throws ApduConnectionException, PaceException {
    final PaceInitializer paceInitializer;
    switch(paceInitType) {
        case MRZ:
            paceInitializer = PaceInitializerMrz.deriveMrz(paceInitValue);
            break;
        case CAN:
        default:
            paceInitializer = new PaceInitializerCan(paceInitValue);
    }
    final SecureMessaging sm = PaceChannelHelper.openPaceChannel((byte) 0x00, // CAN/MRZ
    paceInitializer, con, new JseCryptoHelper());
    // Establecemos el canal PACE
    return new PaceConnection(con, new JseCryptoHelper(), sm);
}
Also used : SecureMessaging(es.gob.jmulticard.de.tsenger.androsmex.iso7816.SecureMessaging) PaceInitializerCan(es.gob.jmulticard.card.pace.PaceInitializerCan) PaceConnection(es.gob.jmulticard.card.pace.PaceConnection) PaceInitializer(es.gob.jmulticard.card.pace.PaceInitializer) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper)

Example 9 with JseCryptoHelper

use of es.gob.jmulticard.JseCryptoHelper in project jmulticard by ctt-gob-es.

the class TestApduEncrypter method testPinEncryptionDes.

/**
 * Prueba de cifrado 3DES de APDU de verificación de PIN.
 * @throws Exception En cualquier error.
 */
@SuppressWarnings("static-method")
@Test
public void testPinEncryptionDes() throws Exception {
    final CommandApdu verifyCommandApdu = new VerifyApduCommand((byte) 0x00, // $NON-NLS-1$
    new CachePasswordCallback("CRYPTOKI".toCharArray()));
    final ApduEncrypter apduEncrypterDes = new ApduEncrypterDes();
    final byte[] res = apduEncrypterDes.protectAPDU(verifyCommandApdu, KENC, KMAC, SSC_PIN, new JseCryptoHelper()).getBytes();
    Assert.assertEquals(// $NON-NLS-1$
    "0c20000019871101ce1ab937c332f3faee43336d4311ef338e046908df4e", HexUtils.hexify(res, false).toLowerCase());
}
Also used : ApduEncrypterDes(es.gob.jmulticard.apdu.connection.ApduEncrypterDes) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) ApduEncrypter(es.gob.jmulticard.apdu.connection.ApduEncrypter) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) VerifyApduCommand(es.gob.jmulticard.apdu.dnie.VerifyApduCommand) Test(org.junit.Test)

Example 10 with JseCryptoHelper

use of es.gob.jmulticard.JseCryptoHelper in project jmulticard by ctt-gob-es.

the class TestApduEncrypter method testEncryptionAes.

/**
 * Prueba de cifrado AES de una APDU.
 * @throws Exception En cualquier error.
 */
@Test
// Necesita el proveedor BC/SC firmado
@Ignore
public void testEncryptionAes() throws Exception {
    this.paddingLength = 16;
    final CommandApdu apdu = new CommandApdu((byte) 0x00, (byte) 0xa4, (byte) 0x04, (byte) 0x00, new byte[] { (byte) 0x4d, (byte) 0x61, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x2e, (byte) 0x46, (byte) 0x69, (byte) 0x6c, (byte) 0x65 }, null);
    System.out.println(HexUtils.hexify(protectAPDU(apdu, KENC2, KMAC2, SSC2, new JseCryptoHelper()).getBytes(), false).toLowerCase());
    System.out.println(HexUtils.hexify(new ApduEncrypterAes().protectAPDU(apdu, KENC2, KMAC2, SSC2, new JseCryptoHelper()).getBytes(), false).toLowerCase());
    // $NON-NLS-1$
    System.out.println("0ca404001d871101f5124ee2f53962e86e66a6d234827f0f8e0870e6de5f679aee64");
}
Also used : CommandApdu(es.gob.jmulticard.apdu.CommandApdu) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) ApduEncrypterAes(es.gob.jmulticard.apdu.connection.ApduEncrypterAes) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

JseCryptoHelper (es.gob.jmulticard.JseCryptoHelper)13 CommandApdu (es.gob.jmulticard.apdu.CommandApdu)4 ApduConnection (es.gob.jmulticard.apdu.connection.ApduConnection)4 Test (org.junit.Test)4 CryptoCardException (es.gob.jmulticard.card.CryptoCardException)3 PinException (es.gob.jmulticard.card.PinException)3 PasswordCallback (javax.security.auth.callback.PasswordCallback)3 ApduEncrypter (es.gob.jmulticard.apdu.connection.ApduEncrypter)2 ApduEncrypterDes (es.gob.jmulticard.apdu.connection.ApduEncrypterDes)2 AuthenticationModeLockedException (es.gob.jmulticard.card.AuthenticationModeLockedException)2 BadPinException (es.gob.jmulticard.card.BadPinException)2 Ceres (es.gob.jmulticard.card.fnmt.ceres.Ceres)2 SmartCafePkcs15Applet (es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet)2 PaceConnection (es.gob.jmulticard.card.pace.PaceConnection)2 PaceInitializer (es.gob.jmulticard.card.pace.PaceInitializer)2 PaceInitializerCan (es.gob.jmulticard.card.pace.PaceInitializerCan)2 SecureMessaging (es.gob.jmulticard.de.tsenger.androsmex.iso7816.SecureMessaging)2 IOException (java.io.IOException)2 KeyStore (java.security.KeyStore)2 PasswordProtection (java.security.KeyStore.PasswordProtection)2