use of es.gob.jmulticard.card.PrivateKeyReference in project jmulticard by ctt-gob-es.
the class SmartCafeKeyStoreImpl method engineGetKey.
/**
* {@inheritDoc}
*/
@Override
public Key engineGetKey(final String alias, final char[] password) {
if (!engineContainsAlias(alias)) {
return null;
}
if (password != null) {
// Establecemos el PasswordCallback
final PasswordCallback pwc = new CachePasswordCallback(password);
this.cryptoCard.setPasswordCallback(pwc);
}
final PrivateKeyReference pkRef = this.cryptoCard.getPrivateKey(alias);
if (!(pkRef instanceof SmartCafePrivateKeyReference)) {
throw new ProviderException(// $NON-NLS-1$
"La clave obtenida de la tarjeta no es del tipo '" + SmartCafePrivateKeyReference.class.getName() + // $NON-NLS-1$
"', se ha obtenido: " + // $NON-NLS-1$
(pkRef != null ? pkRef.getClass().getName() : "null"));
}
return new SmartCafePrivateKey((SmartCafePrivateKeyReference) pkRef, this.cryptoCard);
}
use of es.gob.jmulticard.card.PrivateKeyReference 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.card.PrivateKeyReference 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.card.PrivateKeyReference in project jmulticard by ctt-gob-es.
the class Ceres430KeyStoreImpl method engineGetKey.
/**
* {@inheritDoc}
*/
@Override
public Key engineGetKey(final String alias, final char[] password) {
if (!engineContainsAlias(alias)) {
return null;
}
if (password != null) {
// Establecemos el PasswordCallback
final PasswordCallback pwc = new CachePasswordCallback(password);
this.cryptoCard.setPasswordCallback(pwc);
}
final PrivateKeyReference pkRef = this.cryptoCard.getPrivateKey(alias);
if (!(pkRef instanceof DniePrivateKeyReference)) {
throw new ProviderException(// $NON-NLS-1$ //$NON-NLS-2$
"La clave obtenida de la tarjeta no es del tipo esperado, se ha obtenido: " + (pkRef != null ? pkRef.getClass().getName() : "null"));
}
return new DniePrivateKey((DniePrivateKeyReference) pkRef);
}
use of es.gob.jmulticard.card.PrivateKeyReference in project jmulticard by ctt-gob-es.
the class DnieKeyStoreImpl method engineGetKey.
/**
* {@inheritDoc}
*/
@Override
public Key engineGetKey(final String alias, final char[] password) {
if (!engineContainsAlias(alias)) {
return null;
}
if (password != null) {
// Establecemos el PasswordCallback
final PasswordCallback pwc = new CachePasswordCallback(password);
this.cryptoCard.setPasswordCallback(pwc);
}
final PrivateKeyReference pkRef = this.cryptoCard.getPrivateKey(alias);
if (!(pkRef instanceof DniePrivateKeyReference)) {
throw new ProviderException(// $NON-NLS-1$ //$NON-NLS-2$
"La clave obtenida de la tarjeta no es del tipo esperado, se ha obtenido: " + (pkRef != null ? pkRef.getClass().getName() : "null"));
}
return new DniePrivateKey((DniePrivateKeyReference) pkRef);
}
Aggregations