List of usage examples for org.bouncycastle.asn1.pkcs SignedData SignedData
public SignedData(ASN1Integer _version, ASN1Set _digestAlgorithms, ContentInfo _contentInfo,
ASN1Set _certificates, ASN1Set _crls, ASN1Set _signerInfos)
From source file:ca.trustpoint.m2m.M2mCertPath.java
License:Apache License
/** * Encode the CertPath using PKCS#7 format. * * @return a byte array containing the binary encoding of the PKCS#7 object * @exception CertificateEncodingException if an exception occurs *///from ww w.j a va2 s. c om private byte[] encodePkcs7() throws CertificateEncodingException { ASN1EncodableVector encodedList = new ASN1EncodableVector(); for (M2mCertificate certificate : certificates) { if (isDuplicateCertificate(certificate)) { throw new CertificateEncodingException("Duplicate certificate detected in path."); } try { encodedList.add(ASN1Primitive.fromByteArray(certificate.getEncoded())); } catch (IOException ex) { throw new CertificateEncodingException("Error encoding certificate data.", ex); } } SignedData sd = new SignedData(new ASN1Integer(BigInteger.ONE), // version new DERSet(), // digestAlgorithmIds new ContentInfo(PKCSObjectIdentifiers.data, null), // contentInfo new DERSet(encodedList), // certificates (optional) null, // CRLs (optional) new DERSet() // signerInfos ); // make it a content info sequence ContentInfo ci = new ContentInfo(PKCSObjectIdentifiers.data, sd); try { return ci.getEncoded(); } catch (IOException ex) { throw new CertificateEncodingException("Error encoding certificate path.", ex); } }
From source file:mitm.common.security.asn1.ASN1Encoder.java
License:Open Source License
/** * Taken from org.bouncycastle.jce.provider.PKIXCertPath. * /*w ww .j av a 2s.c om*/ * See ftp://ftp.rsasecurity.com/pub/pkcs/ascii/pkcs-7.asc for info on PKCS#7 encoding */ public static byte[] encodePKCS7(ASN1EncodableVector certificatesVector, ASN1EncodableVector crlsVector) throws IOException { ContentInfo dataContentInfo = new ContentInfo(PKCSObjectIdentifiers.data, null); ASN1Integer version = new ASN1Integer(1); ASN1Set digestAlgorithms = new DERSet(); ASN1Set signerInfos = new DERSet(); ASN1Set crls = null; ASN1Set certificates = null; if (certificatesVector != null) { /* * pre-sort the asn1Certificates vector with a much faster method then DERSet uses */ ASN1EncodableVector sortedASN1Certificates = DERUtils.sortASN1EncodableVector(certificatesVector); certificates = new DERSet(sortedASN1Certificates); } if (crlsVector != null) { /* * pre-sort the asn1Certificates vector with a much faster method then DERSet uses */ ASN1EncodableVector sortedASN1CRLs = DERUtils.sortASN1EncodableVector(crlsVector); crls = new DERSet(sortedASN1CRLs); } SignedData signedData = new SignedData(version, digestAlgorithms, dataContentInfo, certificates, crls, signerInfos); ContentInfo signedContentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, signedData); return DERUtils.toByteArray(signedContentInfo); }