Search in sources :

Example 1 with EncryptionException

use of org.bouncycastle.openssl.EncryptionException in project certmgr by hdecarne.

the class PEMCertReaderWriter method convertKey.

private static KeyPair convertKey(PEMEncryptedKeyPair pemObject, String resource, PasswordCallback password) throws IOException {
    PEMKeyPair pemKeyPair = null;
    Throwable passwordException = null;
    while (pemKeyPair == null) {
        char[] passwordChars = (passwordException == null ? password.queryPassword(resource) : password.requeryPassword(resource, passwordException));
        if (passwordChars == null) {
            throw new PasswordRequiredException(resource, passwordException);
        }
        PEMDecryptorProvider pemDecryptorProvider = PEM_DECRYPTOR_PROVIDER_BUILDER.build(passwordChars);
        try {
            pemKeyPair = pemObject.decryptKeyPair(pemDecryptorProvider);
        } catch (EncryptionException e) {
            passwordException = e;
        }
    }
    return convertKey(pemKeyPair);
}
Also used : PEMDecryptorProvider(org.bouncycastle.openssl.PEMDecryptorProvider) EncryptionException(org.bouncycastle.openssl.EncryptionException) PEMKeyPair(org.bouncycastle.openssl.PEMKeyPair) PasswordRequiredException(de.carne.certmgr.certs.PasswordRequiredException)

Aggregations

PasswordRequiredException (de.carne.certmgr.certs.PasswordRequiredException)1 EncryptionException (org.bouncycastle.openssl.EncryptionException)1 PEMDecryptorProvider (org.bouncycastle.openssl.PEMDecryptorProvider)1 PEMKeyPair (org.bouncycastle.openssl.PEMKeyPair)1