Search in sources :

Example 1 with DniePrivateKeyReference

use of es.gob.jmulticard.card.dnie.DniePrivateKeyReference 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);
}
Also used : DniePrivateKeyReference(es.gob.jmulticard.card.dnie.DniePrivateKeyReference) PrivateKeyReference(es.gob.jmulticard.card.PrivateKeyReference) ProviderException(java.security.ProviderException) CommonPasswordCallback(es.gob.jmulticard.ui.passwordcallback.gui.CommonPasswordCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) DniePrivateKeyReference(es.gob.jmulticard.card.dnie.DniePrivateKeyReference)

Example 2 with DniePrivateKeyReference

use of es.gob.jmulticard.card.dnie.DniePrivateKeyReference 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);
}
Also used : DniePrivateKeyReference(es.gob.jmulticard.card.dnie.DniePrivateKeyReference) PrivateKeyReference(es.gob.jmulticard.card.PrivateKeyReference) ProviderException(java.security.ProviderException) PasswordCallback(javax.security.auth.callback.PasswordCallback) DniePrivateKeyReference(es.gob.jmulticard.card.dnie.DniePrivateKeyReference)

Aggregations

PrivateKeyReference (es.gob.jmulticard.card.PrivateKeyReference)2 DniePrivateKeyReference (es.gob.jmulticard.card.dnie.DniePrivateKeyReference)2 ProviderException (java.security.ProviderException)2 PasswordCallback (javax.security.auth.callback.PasswordCallback)2 CommonPasswordCallback (es.gob.jmulticard.ui.passwordcallback.gui.CommonPasswordCallback)1