use of es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection in project jmulticard by ctt-gob-es.
the class TestAccv method testVerifyPin.
/**
* Prueba de verificación de PIN.
* @throws Exception En cualquier error.
*/
@SuppressWarnings("static-method")
@Test
@Ignore
public void testVerifyPin() throws Exception {
// $NON-NLS-1$
final char[] pin = "11111111".toCharArray();
final Iso7816FourCard card = new SmartCafePkcs15Applet(new SmartcardIoConnection(), new JseCryptoHelper());
card.verifyPin(new CachePasswordCallback(pin));
}
use of es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection in project jmulticard by ctt-gob-es.
the class TestCeres method testCeresUIPasswordCallbackSpecialCharsOnPin.
/**
* Prueba de introducción de PIN por UI, para comprobación de PIN
* con caracteres especiales.
* @throws Exception En cualquier error.
*/
@SuppressWarnings("static-method")
@Test
@Ignore
public void testCeresUIPasswordCallbackSpecialCharsOnPin() throws Exception {
final Ceres ceres = new Ceres(new SmartcardIoConnection(), new JseCryptoHelper());
ceres.setPasswordCallback(// $NON-NLS-1$
new PasswordCallback("PIN de la tarjeta CERES", false));
System.out.println(ceres.getCardName());
System.out.println(Arrays.asList(ceres.getAliases()));
System.out.println(ceres.getCertificate(ceres.getAliases()[0]));
final PrivateKeyReference pkr = ceres.getPrivateKey(ceres.getAliases()[0]);
System.out.println(HexUtils.hexify(// $NON-NLS-1$//$NON-NLS-2$
ceres.sign("hola".getBytes(), "SHA1withRSA", pkr), true));
}
use of es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection in project jmulticard by ctt-gob-es.
the class TestAccv method testSign.
/**
* Prueba de firma.
* @throws Exception En cualquier error.
*/
@SuppressWarnings("static-method")
@Test
@Ignore
public void testSign() throws Exception {
// $NON-NLS-1$
final char[] pin = "11111111".toCharArray();
final SmartCafePkcs15Applet card = new SmartCafePkcs15Applet(new SmartcardIoConnection(), new JseCryptoHelper());
card.setPasswordCallback(new CachePasswordCallback(pin));
final PrivateKeyReference pkr = card.getPrivateKey(card.getAliases()[0]);
// $NON-NLS-1$ //$NON-NLS-2$
final byte[] sign = card.sign("Hola mundo!".getBytes(), "SHA512withRSA", pkr);
System.out.println(HexUtils.hexify(sign, false));
}
use of es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection in project jmulticard by ctt-gob-es.
the class TestDnieChangePIN method testChangePIN.
/**
* Test para probar el cambio de PIN tras la apertura del canal seguro.
* @throws Exception En cualquier error.
*/
@SuppressWarnings("static-method")
@Test
@Ignore
public void testChangePIN() throws Exception {
// $NON-NLS-1$
final CachePasswordCallback cpc = new CachePasswordCallback("password".toCharArray());
final ApduConnection ac = new SmartcardIoConnection();
final Dnie dni = DnieFactory.getDnie(ac, cpc, new JseCryptoHelper(), null);
// $NON-NLS-1$ //$NON-NLS-2$
dni.changePIN("password", "pinNuevo");
}
use of es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection in project jmulticard by ctt-gob-es.
the class TestJseProvider method testProviderWithCustomConnection.
static void testProviderWithCustomConnection() throws Exception {
final Provider p = new DnieProvider(new SmartcardIoConnection());
Security.addProvider(p);
// $NON-NLS-1$
final KeyStore ks = KeyStore.getInstance("DNI");
final CallbackHandler callbackHandler;
// $NON-NLS-1$
callbackHandler = (CallbackHandler) Class.forName("es.gob.jmulticard.ui.passwordcallback.gui.DnieCallbackHandler").getConstructor().newInstance();
final LoadStoreParameter lsp = new LoadStoreParameter() {
@Override
public ProtectionParameter getProtectionParameter() {
return new KeyStore.CallbackHandlerProtection(callbackHandler);
}
};
ks.load(lsp);
final Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
System.out.println(aliases.nextElement());
}
// $NON-NLS-1$
final Signature signature = Signature.getInstance("SHA1withRSA");
// $NON-NLS-1$
signature.initSign((PrivateKey) ks.getKey("CertFirmaDigital", PASSWORD));
// $NON-NLS-1$
signature.update("Hola Mundo!!".getBytes());
signature.sign();
// $NON-NLS-1$
System.out.println("Firma generada correctamente");
}
Aggregations