org.bouncycastle.eac.EACCertificateBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpkix-lts8on Show documentation
Show all versions of bcpkix-lts8on 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.8 and up. The APIs are designed primarily to be used in conjunction with the BC LTS provider but may also be used with other providers providing cryptographic services.
package org.bouncycastle.eac;
import java.io.OutputStream;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.BERTags;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.eac.CVCertificate;
import org.bouncycastle.asn1.eac.CertificateBody;
import org.bouncycastle.asn1.eac.CertificateHolderAuthorization;
import org.bouncycastle.asn1.eac.CertificateHolderReference;
import org.bouncycastle.asn1.eac.CertificationAuthorityReference;
import org.bouncycastle.asn1.eac.EACTags;
import org.bouncycastle.asn1.eac.PackedDate;
import org.bouncycastle.asn1.eac.PublicKeyDataObject;
import org.bouncycastle.eac.operator.EACSigner;
public class EACCertificateBuilder
{
private static final byte [] ZeroArray = new byte [] {0};
private PublicKeyDataObject publicKey;
private CertificateHolderAuthorization certificateHolderAuthorization;
private PackedDate certificateEffectiveDate;
private PackedDate certificateExpirationDate;
private CertificateHolderReference certificateHolderReference;
private CertificationAuthorityReference certificationAuthorityReference;
public EACCertificateBuilder(
CertificationAuthorityReference certificationAuthorityReference,
PublicKeyDataObject publicKey,
CertificateHolderReference certificateHolderReference,
CertificateHolderAuthorization certificateHolderAuthorization,
PackedDate certificateEffectiveDate,
PackedDate certificateExpirationDate)
{
this.certificationAuthorityReference = certificationAuthorityReference;
this.publicKey = publicKey;
this.certificateHolderReference = certificateHolderReference;
this.certificateHolderAuthorization = certificateHolderAuthorization;
this.certificateEffectiveDate = certificateEffectiveDate;
this.certificateExpirationDate = certificateExpirationDate;
}
private CertificateBody buildBody()
{
ASN1TaggedObject certificateProfileIdentifier;
certificateProfileIdentifier = new DERTaggedObject(false, BERTags.APPLICATION,
EACTags.INTERCHANGE_PROFILE, new DEROctetString(ZeroArray));
CertificateBody body = new CertificateBody(
certificateProfileIdentifier,
certificationAuthorityReference,
publicKey,
certificateHolderReference,
certificateHolderAuthorization,
certificateEffectiveDate,
certificateExpirationDate);
return body;
}
public EACCertificateHolder build(EACSigner signer)
throws EACException
{
try
{
CertificateBody body = buildBody();
OutputStream vOut = signer.getOutputStream();
vOut.write(body.getEncoded(ASN1Encoding.DER));
vOut.close();
return new EACCertificateHolder(new CVCertificate(body, signer.getSignature()));
}
catch (Exception e)
{
throw new EACException("unable to process signature: " + e.getMessage(), e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy