org.bouncycastle.pkcs.jcajce.JcePBMac1CalculatorProviderBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpkix-jdk14 Show documentation
Show all versions of bcpkix-jdk14 Show documentation
The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. This jar contains APIs for JDK 1.4. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.
package org.bouncycastle.pkcs.jcajce;
import java.security.Provider;
import org.bouncycastle.asn1.pkcs.PBMAC1Params;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.jcajce.util.DefaultJcaJceHelper;
import org.bouncycastle.jcajce.util.JcaJceHelper;
import org.bouncycastle.jcajce.util.NamedJcaJceHelper;
import org.bouncycastle.jcajce.util.ProviderJcaJceHelper;
import org.bouncycastle.operator.MacCalculator;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.PBEMacCalculatorProvider;
public class JcePBMac1CalculatorProviderBuilder
{
private JcaJceHelper helper = new DefaultJcaJceHelper();
public JcePBMac1CalculatorProviderBuilder()
{
}
public JcePBMac1CalculatorProviderBuilder setProvider(Provider provider)
{
this.helper = new ProviderJcaJceHelper(provider);
return this;
}
public JcePBMac1CalculatorProviderBuilder setProvider(String providerName)
{
this.helper = new NamedJcaJceHelper(providerName);
return this;
}
public PBEMacCalculatorProvider build()
{
return new PBEMacCalculatorProvider()
{
public MacCalculator get(AlgorithmIdentifier algorithm, char[] password)
throws OperatorCreationException
{
if (!PKCSObjectIdentifiers.id_PBMAC1.equals(algorithm.getAlgorithm()))
{
throw new OperatorCreationException("protection algorithm not PB mac based");
}
JcePBMac1CalculatorBuilder bldr
= new JcePBMac1CalculatorBuilder(PBMAC1Params.getInstance(algorithm.getParameters())).setHelper(helper);
return bldr.build(password);
}
};
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy