List of usage examples for org.bouncycastle.asn1 ASN1EncodableVector add
public void add(ASN1Encodable element)
From source file:me.it_result.ca.bouncycastle.Utils.java
License:Open Source License
public static Attribute generateChallengePasswordAttribute(String challengePassword) { ASN1EncodableVector passwordVector = new ASN1EncodableVector(); passwordVector.add(new DERPrintableString(challengePassword)); Attribute passwordAttribute = new Attribute(PKCSObjectIdentifiers.pkcs_9_at_challengePassword, new DERSet(passwordVector)); return passwordAttribute; }
From source file:mitm.common.security.asn1.ASN1Utils.java
License:Open Source License
public static ASN1EncodableVector toASN1EncodableVector(X500Principal principal) throws IOException { final ASN1InputStream stream = new ASN1InputStream(principal.getEncoded()); final ASN1Object der = stream.readObject(); Enumeration<?> e = ASN1Sequence.getInstance(der).getObjects(); ASN1EncodableVector v = new ASN1EncodableVector(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (o instanceof ASN1Encodable) { v.add((ASN1Encodable) o); }/* w w w.j a va 2 s .co m*/ } stream.close(); return v; }
From source file:mitm.common.security.asn1.DERUtils.java
License:Open Source License
/** * Bouncycastle DERSet sorts the entries in the set (required by DER encoding) but uses a slow * sort method. You can use this method to do a pre-sort using a faster method before creating * the DERSet.//from ww w .j a va2 s .co m * @param asn1Certificates * @return * @throws IOException */ public static ASN1EncodableVector sortASN1EncodableVector(ASN1EncodableVector asn1Certificates) throws IOException { ASN1EncodableVector sorted = new ASN1EncodableVector(); List<DEREntry> sortingList = new Vector<DEREntry>(asn1Certificates.size()); for (int i = 0; i < asn1Certificates.size(); i++) { DEREntry entry = new DEREntry(asn1Certificates.get(i)); sortingList.add(entry); } Collections.sort(sortingList); for (DEREntry entry : sortingList) { sorted.add(entry.derEncodable); } return sorted; }
From source file:mitm.common.security.certificate.AltNamesBuilder.java
License:Open Source License
private void addGeneralNames(String[] names, AltNameType altNameType, ASN1EncodableVector altNames) { if (names == null) { return;// w ww . j a v a 2 s.c o m } /* add all the strings */ for (String name : names) { /* * GeneralName encodes the string to the correct DER encoding based * on the tag value */ GeneralName generalName = new GeneralName(altNameType.getTag(), name); altNames.add(generalName); } }
From source file:mitm.common.security.certificate.CertificateEncoder.java
License:Open Source License
private static byte[] encodePKCS7(Collection<? extends Certificate> certificates) throws IOException, CertificateEncodingException { ASN1EncodableVector asn1Certificates = new ASN1EncodableVector(); Iterator<? extends Certificate> certificateIt = certificates.iterator(); while (certificateIt.hasNext()) { Certificate certificate = certificateIt.next(); asn1Certificates.add(DERUtils.toDERObject(certificate)); }//from ww w . j a va 2s . co m return ASN1Encoder.encodePKCS7(asn1Certificates, null /* no CRLs */); }
From source file:mitm.common.security.crl.CRLDistributionPointsBuilder.java
License:Open Source License
public CRLDistPoint buildCRLDistPoint() { if (uris.size() == 0) { return null; }/*from w ww. j ava2 s.c o m*/ CRLDistPoint crlDistPoint; ASN1EncodableVector names = new ASN1EncodableVector(); for (String uri : uris) { GeneralName gn = new GeneralName(GeneralName.uniformResourceIdentifier, new DERIA5String(uri)); names.add(gn); } GeneralNames gns = GeneralNames.getInstance(new DERSequence(names)); DistributionPointName dpn = new DistributionPointName(DistributionPointName.FULL_NAME, gns); DistributionPoint distp = new DistributionPoint(dpn, null, null); crlDistPoint = CRLDistPoint.getInstance(new DERSequence(distp)); return crlDistPoint; }
From source file:mitm.common.security.crl.CRLEncoder.java
License:Open Source License
private static byte[] encodePKCS7(Collection<X509CRL> crls) throws IOException, CRLException { ASN1EncodableVector asn1CRLs = new ASN1EncodableVector(); Iterator<X509CRL> crlIterator = crls.iterator(); while (crlIterator.hasNext()) { X509CRL crl = crlIterator.next(); asn1CRLs.add(DERUtils.toDERObject(crl)); }// w w w.j a va 2 s . c o m return ASN1Encoder.encodePKCS7(null /* no certs */, asn1CRLs); }
From source file:mitm.common.security.crl.PKIXRevocationChecker.java
License:Open Source License
private X500Name getFullName(X500Principal issuer, DistributionPointName distributionPointName) throws IOException { ASN1Encodable rdn = distributionPointName.getName(); X500Name name = null;//from w ww . ja v a 2 s . c om if (rdn != null) { ASN1EncodableVector v = ASN1Utils.toASN1EncodableVector(issuer); v.add(rdn); name = X500Name.getInstance(new DERSequence(v).getEncoded(ASN1Encoding.DER)); } return name; }
From source file:mitm.common.security.smime.SMIMEAttributeUtils.java
License:Open Source License
/** * Returns a AttributeTable with default SMIMECapabilityAttribute and current singing time and * if encryptionCertificate is specified SMIMEEncryptionKeyPreference and OLSMIMEEncryptionKeyPreference * are added as well./* w w w .j a v a2s .c o m*/ * * @throws IOException */ public static AttributeTable getDefaultSignedAttributes(X509Certificate encryptionCertificate) throws IOException { ASN1EncodableVector signedAttrs = new ASN1EncodableVector(); signedAttrs.add(getDefaultSMIMECapabilityAttribute()); signedAttrs.add(getSigningTimeAttribute()); if (encryptionCertificate != null) { signedAttrs.add(getSMIMEEncryptionKeyPreferenceAttribute(encryptionCertificate)); signedAttrs.add(getOLSMIMEEncryptionKeyPreferenceAttribute(encryptionCertificate)); } return new AttributeTable(signedAttrs); }
From source file:net.jsign.asn1.authenticode.AuthenticodeSignedData.java
License:Apache License
public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new ASN1Integer(1)); v.add(new DERSet(digestAlgorithm)); v.add(contentInfo);//ww w .j av a2s. co m if (certificates != null) { v.add(new DERTaggedObject(false, 0, certificates)); } v.add(new DERSet(signerInformation)); return new BERSequence(v); }