All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.jce.X509Principal Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5.

There is a newer version: 1.46
Show newest version
package org.bouncycastle.jce;

import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DEROutputStream;
import org.bouncycastle.asn1.x509.X509Name;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.Principal;
import java.util.Hashtable;
import java.util.Vector;

/**
 * a general extension of X509Name with a couple of extra methods and
 * constructors.
 * 

* Objects of this type can be created from certificates and CRLs using the * PrincipalUtil class. *

* @see org.bouncycastle.jce.PrincipalUtil */ public class X509Principal extends X509Name implements Principal { private static ASN1Sequence readSequence( ASN1InputStream aIn) throws IOException { try { return ASN1Sequence.getInstance(aIn.readObject()); } catch (IllegalArgumentException e) { throw new IOException("not an ASN.1 Sequence: " + e); } } /** * Constructor from an encoded byte array. */ public X509Principal( byte[] bytes) throws IOException { super(readSequence(new ASN1InputStream(bytes))); } /** * Constructor from an X509Name object. */ public X509Principal( X509Name name) { super((ASN1Sequence)name.getDERObject()); } /** * constructor from a table of attributes. *

* it's is assumed the table contains OID/String pairs. */ public X509Principal( Hashtable attributes) { super(attributes); } /** * constructor from a table of attributes and a vector giving the * specific ordering required for encoding or conversion to a string. *

* it's is assumed the table contains OID/String pairs. */ public X509Principal( Vector ordering, Hashtable attributes) { super(ordering, attributes); } /** * constructor from a vector of attribute values and a vector of OIDs. */ public X509Principal( Vector oids, Vector values) { super(oids, values); } /** * takes an X509 dir name as a string of the format "C=AU,ST=Victoria", or * some such, converting it into an ordered set of name attributes. */ public X509Principal( String dirName) { super(dirName); } /** * Takes an X509 dir name as a string of the format "C=AU,ST=Victoria", or * some such, converting it into an ordered set of name attributes. If reverse * is false the dir name will be encoded in the order of the (name, value) pairs * presented, otherwise the encoding will start with the last (name, value) pair * and work back. */ public X509Principal( boolean reverse, String dirName) { super(reverse, dirName); } /** * Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or * some such, converting it into an ordered set of name attributes. lookUp * should provide a table of lookups, indexed by lowercase only strings and * yielding a DERObjectIdentifier, other than that OID. and numeric oids * will be processed automatically. *

* If reverse is true, create the encoded version of the sequence starting * from the last element in the string. */ public X509Principal( boolean reverse, Hashtable lookUp, String dirName) { super(reverse, lookUp, dirName); } public String getName() { return this.toString(); } /** * return a DER encoded byte array representing this object */ public byte[] getEncoded() { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); try { dOut.writeObject(this); } catch (IOException e) { throw new RuntimeException(e.toString()); } return bOut.toByteArray(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy