All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.bouncycastle.openssl.jcajce.JcePEMDecryptorProviderBuilder Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.bouncycastle.openssl.jcajce;

import java.security.Provider;

import com.fitbur.bouncycastle.jcajce.util.DefaultJcaJceHelper;
import com.fitbur.bouncycastle.jcajce.util.JcaJceHelper;
import com.fitbur.bouncycastle.jcajce.util.NamedJcaJceHelper;
import com.fitbur.bouncycastle.jcajce.util.ProviderJcaJceHelper;
import com.fitbur.bouncycastle.openssl.PEMDecryptor;
import com.fitbur.bouncycastle.openssl.PEMDecryptorProvider;
import com.fitbur.bouncycastle.openssl.PEMException;
import com.fitbur.bouncycastle.openssl.PasswordException;

public class JcePEMDecryptorProviderBuilder
{
    private JcaJceHelper helper = new DefaultJcaJceHelper();

    public JcePEMDecryptorProviderBuilder setProvider(Provider provider)
    {
        this.helper = new ProviderJcaJceHelper(provider);

        return this;
    }

    public JcePEMDecryptorProviderBuilder setProvider(String providerName)
    {
        this.helper = new NamedJcaJceHelper(providerName);

        return this;
    }

    public PEMDecryptorProvider build(final char[] password)
    {
        return new PEMDecryptorProvider()
        {
            public PEMDecryptor get(final String com.fitburkAlgName)
            {
                return new PEMDecryptor()
                {
                    public byte[] com.fitburcrypt(byte[] keyBytes, byte[] iv)
                        throws PEMException
                    {
                        if (password == null)
                        {
                            throw new PasswordException("Password is null, but a password is required");
                        }

                        return PEMUtilities.crypt(false, helper, keyBytes, password, com.fitburkAlgName, iv);
                    }
                };
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy