Example usage for org.bouncycastle.asn1.x509 X509NameEntryConverter getConvertedValue

List of usage examples for org.bouncycastle.asn1.x509 X509NameEntryConverter getConvertedValue

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 X509NameEntryConverter getConvertedValue.

Prototype

public abstract ASN1Primitive getConvertedValue(ASN1ObjectIdentifier oid, String value);

Source Link

Document

Convert the passed in String value into the appropriate ASN.1 encoded object.

Usage

From source file:org.glite.slcs.pki.bouncycastle.X509PrincipalUtil.java

License:eu-egee.org license

/**
 * Builds a {@link X509Principal}, based on the given vectors.
 * /* ww w.j ava2s  .c  o  m*/
 * @param ordering
 * @param values
 * @param added
 * @return the {@link X509Principal} or <code>null</code> if an error
 *         occurs.
 * @throws IOException
 *             if a DER encoding error occurs.
 */
private X509Principal buildX509Principal(Vector<DERObjectIdentifier> ordering, Vector<Object> values,
        Vector<Boolean> added) throws IOException {
    X509NameEntryConverter converter = new X509DefaultEntryConverter();
    ASN1EncodableVector vec = new ASN1EncodableVector();
    ASN1EncodableVector sVec = new ASN1EncodableVector();
    DERObjectIdentifier lstOid = null;
    // Bouncycastle's code
    for (int i = 0; i != ordering.size(); i++) {
        ASN1EncodableVector v = new ASN1EncodableVector();
        DERObjectIdentifier oid = ordering.elementAt(i);
        v.add(oid);
        String str = (String) values.elementAt(i);
        v.add(converter.getConvertedValue(oid, str));
        if (lstOid == null || added.elementAt(i)) {
            sVec.add(new DERSequence(v));
        } else {
            vec.add(new DERSet(sVec));
            sVec = new ASN1EncodableVector();
            sVec.add(new DERSequence(v));
        }

        lstOid = oid;
    }
    vec.add(new DERSet(sVec));
    DERSequence seq = new DERSequence(vec);
    byte[] bytes = seq.getDEREncoded();
    return new X509Principal(bytes);
}