Search in sources :

Example 1 with SmartCafePrivateKeyReference

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

Aggregations

PrivateKeyReference (es.gob.jmulticard.card.PrivateKeyReference)1 SmartCafePrivateKeyReference (es.gob.jmulticard.card.gide.smartcafe.SmartCafePrivateKeyReference)1 ProviderException (java.security.ProviderException)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1