Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   package org.bouncycastle.asn1.x509;
   
   import java.io.IOException;
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Vector;
   
     RDNSequence ::= SEQUENCE OF RelativeDistinguishedName

     RelativeDistinguishedName ::= SET SIZE (1..MAX) OF AttributeTypeAndValue

     AttributeTypeAndValue ::= SEQUENCE {
                                   type  OBJECT IDENTIFIER,
                                   value ANY }
 

Deprecated:
use org.bouncycastle.asn1.x500.X500Name.
  
  public class X509Name
      extends ASN1Object
  {
    
country code - StringType(SIZE(2))

Deprecated:
use a X500NameStyle
  
      public static final ASN1ObjectIdentifier C = new ASN1ObjectIdentifier("2.5.4.6");

    
organization - StringType(SIZE(1..64))

Deprecated:
use a X500NameStyle
  
      public static final ASN1ObjectIdentifier O = new ASN1ObjectIdentifier("2.5.4.10");

    
organizational unit name - StringType(SIZE(1..64))

Deprecated:
use a X500NameStyle
  
      public static final ASN1ObjectIdentifier OU = new ASN1ObjectIdentifier("2.5.4.11");

    
Title

Deprecated:
use a X500NameStyle
  
      public static final ASN1ObjectIdentifier T = new ASN1ObjectIdentifier("2.5.4.12");

    
common name - StringType(SIZE(1..64))

Deprecated:
use a X500NameStyle
  
      public static final ASN1ObjectIdentifier CN = new ASN1ObjectIdentifier("2.5.4.3");

    
device serial number name - StringType(SIZE(1..64))
  
      public static final ASN1ObjectIdentifier SN = new ASN1ObjectIdentifier("2.5.4.5");

    
street - StringType(SIZE(1..64))
  
      public static final ASN1ObjectIdentifier STREET = new ASN1ObjectIdentifier("2.5.4.9");
    
    
device serial number name - StringType(SIZE(1..64))
  
      public static final ASN1ObjectIdentifier SERIALNUMBER = ;

    
locality name - StringType(SIZE(1..64))
  
      public static final ASN1ObjectIdentifier L = new ASN1ObjectIdentifier("2.5.4.7");

    
state, or province name - StringType(SIZE(1..64))
  
      public static final ASN1ObjectIdentifier ST = new ASN1ObjectIdentifier("2.5.4.8");

    
Naming attributes of type X520name
  
      public static final ASN1ObjectIdentifier SURNAME = new ASN1ObjectIdentifier("2.5.4.4");
     public static final ASN1ObjectIdentifier GIVENNAME = new ASN1ObjectIdentifier("2.5.4.42");
     public static final ASN1ObjectIdentifier INITIALS = new ASN1ObjectIdentifier("2.5.4.43");
     public static final ASN1ObjectIdentifier GENERATION = new ASN1ObjectIdentifier("2.5.4.44");
     public static final ASN1ObjectIdentifier UNIQUE_IDENTIFIER = new ASN1ObjectIdentifier("2.5.4.45");

    
businessCategory - DirectoryString(SIZE(1..128)
 
     public static final ASN1ObjectIdentifier BUSINESS_CATEGORY = new ASN1ObjectIdentifier(
                     "2.5.4.15");

    
postalCode - DirectoryString(SIZE(1..40)
 
     public static final ASN1ObjectIdentifier POSTAL_CODE = new ASN1ObjectIdentifier(
                     "2.5.4.17");
    
    
dnQualifier - DirectoryString(SIZE(1..64)
 
     public static final ASN1ObjectIdentifier DN_QUALIFIER = new ASN1ObjectIdentifier(
                     "2.5.4.46");

    
RFC 3039 Pseudonym - DirectoryString(SIZE(1..64)
 
     public static final ASN1ObjectIdentifier PSEUDONYM = new ASN1ObjectIdentifier(
                     "2.5.4.65");


    
RFC 3039 DateOfBirth - GeneralizedTime - YYYYMMDD000000Z
 
     public static final ASN1ObjectIdentifier DATE_OF_BIRTH = new ASN1ObjectIdentifier(
                     "1.3.6.1.5.5.7.9.1");

    
RFC 3039 PlaceOfBirth - DirectoryString(SIZE(1..128)
 
     public static final ASN1ObjectIdentifier PLACE_OF_BIRTH = new ASN1ObjectIdentifier(
                     "1.3.6.1.5.5.7.9.2");

    
RFC 3039 Gender - PrintableString (SIZE(1)) -- "M", "F", "m" or "f"
 
     public static final ASN1ObjectIdentifier GENDER = new ASN1ObjectIdentifier(
                     "1.3.6.1.5.5.7.9.3");

    
RFC 3039 CountryOfCitizenship - PrintableString (SIZE (2)) -- ISO 3166 codes only
 
     public static final ASN1ObjectIdentifier COUNTRY_OF_CITIZENSHIP = new ASN1ObjectIdentifier(
                     "1.3.6.1.5.5.7.9.4");

    
RFC 3039 CountryOfResidence - PrintableString (SIZE (2)) -- ISO 3166 codes only
 
     public static final ASN1ObjectIdentifier COUNTRY_OF_RESIDENCE = new ASN1ObjectIdentifier(
                     "1.3.6.1.5.5.7.9.5");


    
ISIS-MTT NameAtBirth - DirectoryString(SIZE(1..64)
 
     public static final ASN1ObjectIdentifier NAME_AT_BIRTH =  new ASN1ObjectIdentifier("1.3.36.8.3.14");

    
RFC 3039 PostalAddress - SEQUENCE SIZE (1..6) OF DirectoryString(SIZE(1..30))
 
     public static final ASN1ObjectIdentifier POSTAL_ADDRESS = new ASN1ObjectIdentifier("2.5.4.16");

    
RFC 2256 dmdName
 
     public static final ASN1ObjectIdentifier DMD_NAME = new ASN1ObjectIdentifier("2.5.4.54");

    
id-at-telephoneNumber
 
id-at-name
 
     public static final ASN1ObjectIdentifier NAME = .;

    
Email address (RSA PKCS#9 extension) - IA5String.

Note: if you're trying to be ultra orthodox, don't use this! It shouldn't be in here.

Deprecated:
use a X500NameStyle
 
     public static final ASN1ObjectIdentifier EmailAddress = .;
    
    
more from PKCS#9
 
email address in Verisign certificates
 
     public static final ASN1ObjectIdentifier E = ;
     
     /*
      * others...
      */
     public static final ASN1ObjectIdentifier DC = new ASN1ObjectIdentifier("0.9.2342.19200300.100.1.25");

    
LDAP User id.
 
     public static final ASN1ObjectIdentifier UID = new ASN1ObjectIdentifier("0.9.2342.19200300.100.1.1");

    
determines whether or not strings should be processed and printed from back to front.
 
     public static boolean DefaultReverse = false;

    
default look up table translating OID values into their common symbols following the convention in RFC 2253 with a few extras
 
     public static final Hashtable DefaultSymbols = new Hashtable();

    
look up table translating OID values into their common symbols following the convention in RFC 2253
 
     public static final Hashtable RFC2253Symbols = new Hashtable();

    
look up table translating OID values into their common symbols following the convention in RFC 1779
 
     public static final Hashtable RFC1779Symbols = new Hashtable();

    
look up table translating common symbols into their OIDS.
 
     public static final Hashtable DefaultLookUp = new Hashtable();

    
look up table translating OID values into their common symbols

Deprecated:
use DefaultSymbols
 
     public static final Hashtable OIDLookUp = ;

    
look up table translating string values into their OIDS -

Deprecated:
use DefaultLookUp
 
     public static final Hashtable SymbolLookUp = ;
 
     private static final Boolean TRUE = new Boolean(true); // for J2ME compatibility
     private static final Boolean FALSE = new Boolean(false);
 
     static
     {
         .put("C");
         .put("O");
         .put("T");
         .put("OU");
         .put("CN");
         .put("L");
         .put("ST");
         .put("SERIALNUMBER");
         .put("E");
         .put("DC");
         .put("UID");
         .put("STREET");
         .put("SURNAME");
         .put("GIVENNAME");
         .put("INITIALS");
         .put("GENERATION");
         .put("unstructuredAddress");
         .put("unstructuredName");
         .put("UniqueIdentifier");
         .put("DN");
         .put("Pseudonym");
         .put("PostalAddress");
         .put("NameAtBirth");
         .put("CountryOfCitizenship");
         .put("CountryOfResidence");
         .put("Gender");
         .put("PlaceOfBirth");
         .put("DateOfBirth");
         .put("PostalCode");
         .put("BusinessCategory");
         .put("TelephoneNumber");
         .put("Name");
 
         .put("C");
         .put("O");
         .put("OU");
         .put("CN");
         .put("L");
         .put("ST");
         .put("STREET");
         .put("DC");
         .put("UID");
 
         .put("C");
         .put("O");
         .put("OU");
         .put("CN");
         .put("L");
         .put("ST");
         .put("STREET");
 
         .put("c");
         .put("o");
         .put("t");
         .put("ou");
         .put("cn");
         .put("l");
         .put("st");
         .put("sn");
         .put("serialnumber");
         .put("street");
         .put("emailaddress");
         .put("dc");
         .put("e");
         .put("uid");
         .put("surname");
         .put("givenname");
         .put("initials");
         .put("generation");
         .put("unstructuredaddress");
         .put("unstructuredname");
         .put("uniqueidentifier");
         .put("dn");
         .put("pseudonym");
         .put("postaladdress");
         .put("nameofbirth");
         .put("countryofcitizenship");
         .put("countryofresidence");
         .put("gender");
         .put("placeofbirth");
         .put("dateofbirth");
         .put("postalcode");
         .put("businesscategory");
         .put("telephonenumber");
         .put("name");
     }
 
     private X509NameEntryConverter  converter = null;
     private Vector                  ordering = new Vector();
     private Vector                  values = new Vector();
     private Vector                  added = new Vector();
 
     private ASN1Sequence            seq;
 
     private boolean                 isHashCodeCalculated;
     private int                     hashCodeValue;

    
Return a X509Name based on the passed in tagged object.

Parameters:
obj tag object holding name.
explicit true if explicitly tagged false otherwise.
Returns:
the X509Name
 
     public static X509Name getInstance(
         ASN1TaggedObject obj,
         boolean          explicit)
     {
         return getInstance(ASN1Sequence.getInstance(objexplicit));
     }
 
     public static X509Name getInstance(
         Object  obj)
     {
         if (obj == null || obj instanceof X509Name)
         {
             return (X509Name)obj;
         }
         else if (obj instanceof X500Name)
         {
             return new X509Name(ASN1Sequence.getInstance(((X500Name)obj).toASN1Primitive()));
         }
         else if (obj != null)
         {
             return new X509Name(ASN1Sequence.getInstance(obj));
         }
 
         return null;
     }
 
     protected X509Name()
     {
         // constructure use by new X500 Name class
     }
    
Constructor from ASN1Sequence the principal will be a list of constructed sets, each containing an (OID, String) pair.

Deprecated:
use X500Name.getInstance()
 
     public X509Name(
         ASN1Sequence  seq)
     {
         this. = seq;
 
         Enumeration e = seq.getObjects();
 
         while (e.hasMoreElements())
         {
             ASN1Set         set = ASN1Set.getInstance(((ASN1Encodable)e.nextElement()).toASN1Primitive());
 
             for (int i = 0; i < set.size(); i++) 
             {
                    ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i).toASN1Primitive());
 
                    if (s.size() != 2)
                    {
                        throw new IllegalArgumentException("badly sized pair");
                    }
 
                    .addElement(ASN1ObjectIdentifier.getInstance(s.getObjectAt(0)));
                    
                    ASN1Encodable value = s.getObjectAt(1);
                    if (value instanceof ASN1String && !(value instanceof DERUniversalString))
                    {
                        String v = ((ASN1String)value).getString();
                        if (v.length() > 0 && v.charAt(0) == '#')
                        {
                            .addElement("\\" + v);
                        }
                        else
                        {
                            .addElement(v);
                        }
                    }
                    else
                    {
                        try
                        {
                            .addElement("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(.))));
                        }
                        catch (IOException e1)
                        {
                            throw new IllegalArgumentException("cannot encode value");
                        }
                    }
                    .addElement((i != 0) ?  : );  // to allow earlier JDK compatibility
             }
         }
     }

    
constructor from a table of attributes.

it's is assumed the table contains OID/String pairs, and the contents of the table are copied into an internal table as part of the construction process.

Note: if the name you are trying to generate should be following a specific ordering, you should use the constructor with the ordering specified below.

Deprecated:
use an ordered constructor! The hashtable ordering is rarely correct
 
     public X509Name(
         Hashtable  attributes)
     {
         this(nullattributes);
     }

    
Constructor from a table of attributes with ordering.

it's is assumed the table contains OID/String pairs, and the contents of the table are copied into an internal table as part of the construction process. The ordering vector should contain the OIDs in the order they are meant to be encoded or printed in toString.

 
     public X509Name(
         Vector      ordering,
         Hashtable   attributes)
     {
         this(orderingattributesnew X509DefaultEntryConverter());
     }

    
Constructor from a table of attributes with ordering.

it's is assumed the table contains OID/String pairs, and the contents of the table are copied into an internal table as part of the construction process. The ordering vector should contain the OIDs in the order they are meant to be encoded or printed in toString.

The passed in converter will be used to convert the strings into their ASN.1 counterparts.

Deprecated:
use X500Name, X500NameBuilder
 
     public X509Name(
         Vector                   ordering,
         Hashtable                attributes,
         X509NameEntryConverter   converter)
     {
         this. = converter;
 
         if (ordering != null)
         {
             for (int i = 0; i != ordering.size(); i++)
             {
                 this..addElement(ordering.elementAt(i));
                 this..addElement();
             }
         }
         else
         {
             Enumeration     e = attributes.keys();
 
             while (e.hasMoreElements())
             {
                 this..addElement(e.nextElement());
                 this..addElement();
             }
         }
 
         for (int i = 0; i != this..size(); i++)
         {
             ASN1ObjectIdentifier     oid = (ASN1ObjectIdentifier)this..elementAt(i);
 
             if (attributes.get(oid) == null)
             {
                 throw new IllegalArgumentException("No attribute for object id - " + oid.getId() + " - passed to distinguished name");
             }
 
             this..addElement(attributes.get(oid)); // copy the hash table
         }
     }

    
Takes two vectors one of the oids and the other of the values.

Deprecated:
use X500Name, X500NameBuilder
 
     public X509Name(
         Vector  oids,
         Vector  values)
     {
         this(oidsvaluesnew X509DefaultEntryConverter());
     }

    
Takes two vectors one of the oids and the other of the values.

The passed in converter will be used to convert the strings into their ASN.1 counterparts.

Deprecated:
use X500Name, X500NameBuilder
 
     public X509Name(
         Vector                  oids,
         Vector                  values,
         X509NameEntryConverter  converter)
     {
         this. = converter;
 
         if (oids.size() != values.size())
         {
             throw new IllegalArgumentException("oids vector must be same length as values.");
         }
 
         for (int i = 0; i < oids.size(); i++)
         {
             this..addElement(oids.elementAt(i));
             this..addElement(values.elementAt(i));
             this..addElement();
         }
     }
 
 //    private Boolean isEncoded(String s)
 //    {
 //        if (s.charAt(0) == '#')
 //        {
 //            return TRUE;
 //        }
 //
 //        return FALSE;
 //    }
 
    
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.

Deprecated:
use X500Name, X500NameBuilder
 
     public X509Name(
         String  dirName)
     {
         this(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 with each string value being converted to its associated ASN.1 type using the passed in converter.

Deprecated:
use X500Name, X500NameBuilder
 
     public X509Name(
         String                  dirName,
         X509NameEntryConverter  converter)
     {
         this(dirNameconverter);
     }

    
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 true, create the encoded version of the sequence starting from the last element in the string.

Deprecated:
use X500Name, X500NameBuilder
 
     public X509Name(
         boolean reverse,
         String  dirName)
     {
         this(reversedirName);
     }

    
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 with each string value being converted to its associated ASN.1 type using the passed in converter. If reverse is true the ASN.1 sequence representing the DN will be built by starting at the end of the string, rather than the start.

Deprecated:
use X500Name, X500NameBuilder
 
     public X509Name(
         boolean                 reverse,
         String                  dirName,
         X509NameEntryConverter  converter)
     {
         this(reversedirNameconverter);
     }

    
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 ASN1ObjectIdentifier, 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.

Deprecated:
use X500Name, X500NameBuilder
Parameters:
reverse true if we should start scanning from the end (RFC 2553).
lookUp table of names and their oids.
dirName the X.500 string to be parsed.
 
     public X509Name(
         boolean     reverse,
         Hashtable   lookUp,
         String      dirName)
     {
         this(reverselookUpdirNamenew X509DefaultEntryConverter());
     }
 
     private ASN1ObjectIdentifier decodeOID(
         String      name,
         Hashtable   lookUp)
     {
         name = name.trim();
         if (Strings.toUpperCase(name).startsWith("OID."))
         {
             return new ASN1ObjectIdentifier(name.substring(4));
         }
         else if (name.charAt(0) >= '0' && name.charAt(0) <= '9')
         {
             return new ASN1ObjectIdentifier(name);
         }
 
         ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)lookUp.get(Strings.toLowerCase(name));
         if (oid == null)
         {
             throw new IllegalArgumentException("Unknown object id - " + name + " - passed to distinguished name");
         }
 
         return oid;
     }
 
     private String unescape(String elt)
     {
         if (elt.length() == 0 || (elt.indexOf('\\') < 0 && elt.indexOf('"') < 0))
         {
             return elt.trim();
         }
 
         char[] elts = elt.toCharArray();
         boolean escaped = false;
         boolean quoted = false;
         StringBuffer buf = new StringBuffer(elt.length());
         int start = 0;
 
         // if it's an escaped hash string and not an actual encoding in string form
         // we need to leave it escaped.
         if (elts[0] == '\\')
         {
             if (elts[1] == '#')
             {
                 start = 2;
                 buf.append("\\#");
             }
         }
 
         boolean nonWhiteSpaceEncountered = false;
         int     lastEscaped = 0;
 
         for (int i = starti != elts.lengthi++)
         {
             char c = elts[i];
 
             if (c != ' ')
             {
                 nonWhiteSpaceEncountered = true;
             }
 
             if (c == '"')
             {
                 if (!escaped)
                 {
                     quoted = !quoted;
                 }
                 else
                 {
                     buf.append(c);
                 }
                 escaped = false;
             }
             else if (c == '\\' && !(escaped || quoted))
             {
                 escaped = true;
                 lastEscaped = buf.length();
             }
             else
             {
                 if (c == ' ' && !escaped && !nonWhiteSpaceEncountered)
                 {
                     continue;
                 }
                 buf.append(c);
                 escaped = false;
             }
         }
 
         if (buf.length() > 0)
         {
             while (buf.charAt(buf.length() - 1) == ' ' && lastEscaped != (buf.length() - 1))
             {
                 buf.setLength(buf.length() - 1);
             }
         }
 
         return buf.toString();
     }

    
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 ASN1ObjectIdentifier, other than that OID. and numeric oids will be processed automatically. The passed in converter is used to convert the string values to the right of each equals sign to their ASN.1 counterparts.

Parameters:
reverse true if we should start scanning from the end, false otherwise.
lookUp table of names and oids.
dirName the string dirName
converter the converter to convert string values into their ASN.1 equivalents
 
     public X509Name(
         boolean                 reverse,
         Hashtable               lookUp,
         String                  dirName,
         X509NameEntryConverter  converter)
     {
         this. = converter;
         X509NameTokenizer   nTok = new X509NameTokenizer(dirName);
 
         while (nTok.hasMoreTokens())
         {
             String  token = nTok.nextToken();
 
             if (token.indexOf('+') > 0)
             {
                 X509NameTokenizer   pTok = new X509NameTokenizer(token'+');
 
                 addEntry(lookUppTok.nextToken(), );
 
                 while (pTok.hasMoreTokens())
                 {
                     addEntry(lookUppTok.nextToken(), );
                 }
             }
             else
             {
                 addEntry(lookUptoken);
             }
         }
 
         if (reverse)
         {
             Vector  o = new Vector();
             Vector  v = new Vector();
             Vector  a = new Vector();
 
             int count = 1;
 
             for (int i = 0; i < this..size(); i++)
             {
                 if (((Boolean)this..elementAt(i)).booleanValue())
                 {
                     o.insertElementAt(this..elementAt(i), count);
                     v.insertElementAt(this..elementAt(i), count);
                     a.insertElementAt(this..elementAt(i), count);
                     count++;
                 }
                 else
                 {
                     o.insertElementAt(this..elementAt(i), 0);
                     v.insertElementAt(this..elementAt(i), 0);
                     a.insertElementAt(this..elementAt(i), 0);
                     count = 1;
                 }
             }
 
             this. = o;
             this. = v;
             this. = a;
         }
     }
 
     private void addEntry(Hashtable lookUpString tokenBoolean isAdded)
     {
         X509NameTokenizer vTok;
         String name;
         String value;ASN1ObjectIdentifier oid;
         vTok = new X509NameTokenizer(token'=');
 
         name = vTok.nextToken();
 
         if (!vTok.hasMoreTokens())
         {
            throw new IllegalArgumentException("badly formatted directory string");
         }
 
         value = vTok.nextToken();
 
         oid = decodeOID(namelookUp);
 
         this..addElement(oid);
         this..addElement(unescape(value));
         this..addElement(isAdded);
     }

    
return a vector of the oids in the name, in the order they were found.
 
     public Vector getOIDs()
     {
         Vector  v = new Vector();
 
         for (int i = 0; i != .size(); i++)
         {
             v.addElement(.elementAt(i));
         }
 
         return v;
     }

    
return a vector of the values found in the name, in the order they were found.
 
     public Vector getValues()
     {
         Vector  v = new Vector();
 
         for (int i = 0; i != .size(); i++)
         {
             v.addElement(.elementAt(i));
         }
 
         return v;
     }

    
return a vector of the values found in the name, in the order they were found, with the DN label corresponding to passed in oid.
 
     public Vector getValues(
         ASN1ObjectIdentifier oid)
     {
         Vector  v = new Vector();
 
         for (int i = 0; i != .size(); i++)
         {
             if (.elementAt(i).equals(oid))
             {
                 String val = (String).elementAt(i);
 
                 if (val.length() > 2 && val.charAt(0) == '\\' && val.charAt(1) == '#')
                 {
                     v.addElement(val.substring(1));
                 }
                 else
                 {
                     v.addElement(val);
                 }
             }
         }
 
         return v;
     }
 
     public ASN1Primitive toASN1Primitive()
     {
         if ( == null)
         {
             ASN1EncodableVector  vec = new ASN1EncodableVector();
             ASN1EncodableVector  sVec = new ASN1EncodableVector();
             ASN1ObjectIdentifier  lstOid = null;
             
             for (int i = 0; i != .size(); i++)
             {
                 ASN1EncodableVector     v = new ASN1EncodableVector();
                 ASN1ObjectIdentifier     oid = (ASN1ObjectIdentifier).elementAt(i);
 
                 v.add(oid);
 
                 String  str = (String).elementAt(i);
 
                 v.add(.getConvertedValue(oidstr));
  
                 if (lstOid == null 
                     || ((Boolean)this..elementAt(i)).booleanValue())
                 {
                     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));
             
              = new DERSequence(vec);
         }
 
         return ;
     }

    

Parameters:
inOrder if true the order of both X509 names must be the same, as well as the values associated with each element.
 
     public boolean equals(Object objboolean inOrder)
     {
         if (!inOrder)
         {
             return this.equals(obj);
         }
 
         if (obj == this)
         {
             return true;
         }
 
         if (!(obj instanceof X509Name || obj instanceof ASN1Sequence))
         {
             return false;
         }
 
         ASN1Primitive derO = ((ASN1Encodable)obj).toASN1Primitive();
 
         if (this.toASN1Primitive().equals(derO))
         {
             return true;
         }
 
         X509Name other;
 
         try
         {
             other = X509Name.getInstance(obj);
         }
         catch (IllegalArgumentException e)
         {
             return false;
         }
        int      orderingSize = .size();
        if (orderingSize != other.ordering.size())
        {
            return false;
        }
        for (int i = 0; i < orderingSizei++)
        {
            ASN1ObjectIdentifier  oid = (ASN1ObjectIdentifier).elementAt(i);
            ASN1ObjectIdentifier  oOid = (ASN1ObjectIdentifier)other.ordering.elementAt(i);
            if (oid.equals(oOid))
            {
                String value = (String).elementAt(i);
                String oValue = (String)other.values.elementAt(i);
                if (!equivalentStrings(valueoValue))
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        return true;
    }
    public int hashCode()
    {
        if ()
        {
            return ;
        }
         = true;
        // this needs to be order independent, like equals
        for (int i = 0; i != .size(); i += 1)
        {
            String value = (String).elementAt(i);
            value = canonicalize(value);
            value = stripInternalSpaces(value);
             ^= .elementAt(i).hashCode();
             ^= value.hashCode();
        }
        return ;
    }

    
test for equality - note: case is ignored.
    public boolean equals(Object obj)
    {
        if (obj == this)
        {
            return true;
        }
        if (!(obj instanceof X509Name || obj instanceof ASN1Sequence))
        {
            return false;
        }
        
        ASN1Primitive derO = ((ASN1Encodable)obj).toASN1Primitive();
        
        if (this.toASN1Primitive().equals(derO))
        {
            return true;
        }
        X509Name other;
        try
        {
            other = X509Name.getInstance(obj);
        }
        catch (IllegalArgumentException e)
        { 
            return false;
        }
        int      orderingSize = .size();
        if (orderingSize != other.ordering.size())
        {
            return false;
        }
        
        boolean[] indexes = new boolean[orderingSize];
        int       startenddelta;
        if (.elementAt(0).equals(other.ordering.elementAt(0)))   // guess forward
        {
            start = 0;
            end = orderingSize;
            delta = 1;
        }
        else  // guess reversed - most common problem
        {
            start = orderingSize - 1;
            end = -1;
            delta = -1;
        }
        for (int i = starti != endi += delta)
        {
            boolean              found = false;
            ASN1ObjectIdentifier  oid = (ASN1ObjectIdentifier).elementAt(i);
            String               value = (String).elementAt(i);
            for (int j = 0; j < orderingSizej++)
            {
                if (indexes[j])
                {
                    continue;
                }
                ASN1ObjectIdentifier oOid = (ASN1ObjectIdentifier)other.ordering.elementAt(j);
                if (oid.equals(oOid))
                {
                    String oValue = (String)other.values.elementAt(j);
                    if (equivalentStrings(valueoValue))
                    {
                        indexes[j] = true;
                        found      = true;
                        break;
                    }
                }
            }
            if (!found)
            {
                return false;
            }
        }
        
        return true;
    }
    private boolean equivalentStrings(String s1String s2)
    {
        String value = canonicalize(s1);
        String oValue = canonicalize(s2);
        
        if (!value.equals(oValue))
        {
            value = stripInternalSpaces(value);
            oValue = stripInternalSpaces(oValue);
            if (!value.equals(oValue))
            {
                return false;
            }
        }
        return true;
    }
    private String canonicalize(String s)
    {
        String value = Strings.toLowerCase(s.trim());
        
        if (value.length() > 0 && value.charAt(0) == '#')
        {
            ASN1Primitive obj = decodeObject(value);
            if (obj instanceof ASN1String)
            {
                value = Strings.toLowerCase(((ASN1String)obj).getString().trim());
            }
        }
        return value;
    }
    private ASN1Primitive decodeObject(String oValue)
    {
        try
        {
            return ASN1Primitive.fromByteArray(Hex.decode(oValue.substring(1)));
        }
        catch (IOException e)
        {
            throw new IllegalStateException("unknown encoding in name: " + e);
        }
    }
    private String stripInternalSpaces(
        String str)
    {
        StringBuffer res = new StringBuffer();
        if (str.length() != 0)
        {
            char    c1 = str.charAt(0);
            res.append(c1);
            for (int k = 1; k < str.length(); k++)
            {
                char    c2 = str.charAt(k);
                if (!(c1 == ' ' && c2 == ' '))
                {
                    res.append(c2);
                }
                c1 = c2;
            }
        }
        return res.toString();
    }
    private void appendValue(
        StringBuffer        buf,
        Hashtable           oidSymbols,
        ASN1ObjectIdentifier oid,
        String              value)
    {
        String  sym = (String)oidSymbols.get(oid);
        if (sym != null)
        {
            buf.append(sym);
        }
        else
        {
            buf.append(oid.getId());
        }
        buf.append('=');
        int start = buf.length();
        buf.append(value);
        int end = buf.length();
        if (value.length() >= 2 && value.charAt(0) == '\\' && value.charAt(1) == '#')
        {
            start += 2;
        }
        while (start < end && buf.charAt(start) == ' ')
        {
            buf.insert(start"\\");
            start += 2;
            ++end;
        }
        while (--end > start && buf.charAt(end) == ' ')
        {
            buf.insert(end'\\');
        }
        while (start <= end)
        {
            switch (buf.charAt(start))
            {
            case ',':
            case '"':
            case '\\':
            case '+':
            case '=':
            case '<':
            case '>':
            case ';':
                buf.insert(start"\\");
                start += 2;
                ++end;
                break;
            default:
                ++start;
                break;
            }
        }
    }

    
convert the structure to a string - if reverse is true the oids and values are listed out starting with the last element in the sequence (ala RFC 2253), otherwise the string will begin with the first element of the structure. If no string definition for the oid is found in oidSymbols the string value of the oid is added. Two standard symbol tables are provided DefaultSymbols, and RFC2253Symbols as part of this class.

Parameters:
reverse if true start at the end of the sequence and work back.
oidSymbols look up table strings for oids.
    public String toString(
        boolean     reverse,
        Hashtable   oidSymbols)
    {
        StringBuffer            buf = new StringBuffer();
        Vector                  components = new Vector();
        boolean                 first = true;
        StringBuffer ava = null;
        for (int i = 0; i < .size(); i++)
        {
            if (((Boolean).elementAt(i)).booleanValue())
            {
                ava.append('+');
                appendValue(avaoidSymbols,
                    (ASN1ObjectIdentifier).elementAt(i),
                    (String).elementAt(i));
            }
            else
            {
                ava = new StringBuffer();
                appendValue(avaoidSymbols,
                    (ASN1ObjectIdentifier).elementAt(i),