Search in sources :

Example 1 with KeyringConfigCallback

use of name.neuhalfen.projects.crypto.bouncycastle.openpgp.keys.callbacks.KeyringConfigCallback in project iaf by ibissource.

the class PGPAction method configure.

/**
 * Generates a keyring configuration with public keys and the private key.
 *
 * @throws ConfigurationException When the files do not exist, or unexpected PGP exception has occurred.
 */
public void configure() throws ConfigurationException {
    try {
        // Create configuration
        KeyringConfigCallback callback = KeyringConfigCallbacks.withUnprotectedKeys();
        if (secretPassword != null)
            callback = KeyringConfigCallbacks.withPassword(secretPassword);
        keyringConfig = KeyringConfigs.forGpgExportedKeys(callback);
        // Add public keys
        if (publicKeys != null) {
            for (String s : publicKeys) {
                URL url = ClassUtils.getResourceURL(this, s);
                keyringConfig.addPublicKey(IOUtils.toByteArray(url.openStream()));
            }
        }
        // Add private key
        if (secretKey != null) {
            URL url = ClassUtils.getResourceURL(this, secretKey);
            keyringConfig.addSecretKey(IOUtils.toByteArray(url.openStream()));
        }
    } catch (IOException | PGPException e) {
        throw new ConfigurationException("Unknown exception has occurred.", e);
    }
}
Also used : PGPException(org.bouncycastle.openpgp.PGPException) KeyringConfigCallback(name.neuhalfen.projects.crypto.bouncycastle.openpgp.keys.callbacks.KeyringConfigCallback) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)1 URL (java.net.URL)1 KeyringConfigCallback (name.neuhalfen.projects.crypto.bouncycastle.openpgp.keys.callbacks.KeyringConfigCallback)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 PGPException (org.bouncycastle.openpgp.PGPException)1