org.bouncycastle.cms.CMSPatchKit 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.
package org.bouncycastle.cms;
import java.io.IOException;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.cms.SignerInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
/**
* Toolkit methods for dealing with common errors in CMS
* classes.
*/
public class CMSPatchKit
{
/**
* Create a SignerInformation based on original which uses definite-length
* rather than DER encoding for verifying the signature on the signed attributes.
*
* @param original the source SignerInformation
*/
public static SignerInformation createNonDERSignerInfo(
SignerInformation original)
{
return new DLSignerInformation(original);
}
/**
* Create a SignerInformation based on original has it's signatureAlgorithm replaced
* with the passed in AlgorithmIdentifier.
*
* @param original the source SignerInformation
*/
public static SignerInformation createWithSignatureAlgorithm(
SignerInformation original,
AlgorithmIdentifier signatureAlgorithm)
{
return new ModEncAlgSignerInformation(original, signatureAlgorithm);
}
private static class DLSignerInformation
extends SignerInformation
{
protected DLSignerInformation(SignerInformation baseInfo)
{
super(baseInfo);
}
public byte[] getEncodedSignedAttributes()
throws IOException
{
return signedAttributeSet.getEncoded(ASN1Encoding.DL);
}
}
private static class ModEncAlgSignerInformation
extends SignerInformation
{
protected ModEncAlgSignerInformation(
SignerInformation baseInfo,
AlgorithmIdentifier signatureAlgorithm)
{
super(baseInfo, editEncAlg(baseInfo.info, signatureAlgorithm));
}
private static SignerInfo editEncAlg(SignerInfo info, AlgorithmIdentifier signatureAlgorithm)
{
return new SignerInfo(info.getSID(), info.getDigestAlgorithm(), info.getAuthenticatedAttributes(),
signatureAlgorithm, info.getEncryptedDigest(), info.getUnauthenticatedAttributes());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy