org.bouncycastle.cms.SignerInformationVerifier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpkix-jdk15on Show documentation
Show all versions of bcpkix-jdk15on 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.5 to JDK 1.8. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.
The newest version!
package org.bouncycastle.cms;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.operator.ContentVerifier;
import org.bouncycastle.operator.ContentVerifierProvider;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.SignatureAlgorithmIdentifierFinder;
public class SignerInformationVerifier
{
private ContentVerifierProvider verifierProvider;
private DigestCalculatorProvider digestProvider;
private SignatureAlgorithmIdentifierFinder sigAlgorithmFinder;
private CMSSignatureAlgorithmNameGenerator sigNameGenerator;
public SignerInformationVerifier(CMSSignatureAlgorithmNameGenerator sigNameGenerator, SignatureAlgorithmIdentifierFinder sigAlgorithmFinder, ContentVerifierProvider verifierProvider, DigestCalculatorProvider digestProvider)
{
this.sigNameGenerator = sigNameGenerator;
this.sigAlgorithmFinder = sigAlgorithmFinder;
this.verifierProvider = verifierProvider;
this.digestProvider = digestProvider;
}
public boolean hasAssociatedCertificate()
{
return verifierProvider.hasAssociatedCertificate();
}
public X509CertificateHolder getAssociatedCertificate()
{
return verifierProvider.getAssociatedCertificate();
}
public ContentVerifier getContentVerifier(AlgorithmIdentifier signingAlgorithm, AlgorithmIdentifier digestAlgorithm)
throws OperatorCreationException
{
String signatureName = sigNameGenerator.getSignatureName(digestAlgorithm, signingAlgorithm);
AlgorithmIdentifier baseAlgID = sigAlgorithmFinder.find(signatureName);
return verifierProvider.get(new AlgorithmIdentifier(baseAlgID.getAlgorithm(), signingAlgorithm.getParameters()));
}
public DigestCalculator getDigestCalculator(AlgorithmIdentifier algorithmIdentifier)
throws OperatorCreationException
{
return digestProvider.get(algorithmIdentifier);
}
}