⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x509name.java

📁 kmlnjlkj nlkjlkjkljl okopokipoipo oipipipo i
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                           values.addElement(v);                       }                   }                   else                   {                       values.addElement("#" + bytesToString(Hex.encode(value.getDERObject().getDEREncoded())));                   }                   added.addElement((i != 0) ? TRUE : FALSE);  // to allow earlier JDK compatibility            }        }    }    /**     * constructor from a table of attributes.     * <p>     * 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.     * <p>     * <b>Note:</b> 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(null, attributes);    }    /**     * Constructor from a table of attributes with ordering.     * <p>     * 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(ordering, attributes, new X509DefaultEntryConverter());    }    /**     * Constructor from a table of attributes with ordering.     * <p>     * 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.     * <p>     * The passed in converter will be used to convert the strings into their     * ASN.1 counterparts.     */    public X509Name(        Vector                   ordering,        Hashtable                attributes,        X509NameEntryConverter   converter)    {        this.converter = converter;        if (ordering != null)        {            for (int i = 0; i != ordering.size(); i++)            {                this.ordering.addElement(ordering.elementAt(i));                this.added.addElement(FALSE);            }        }        else        {            Enumeration     e = attributes.keys();            while (e.hasMoreElements())            {                this.ordering.addElement(e.nextElement());                this.added.addElement(FALSE);            }        }        for (int i = 0; i != this.ordering.size(); i++)        {            DERObjectIdentifier     oid = (DERObjectIdentifier)this.ordering.elementAt(i);            if (attributes.get(oid) == null)            {                throw new IllegalArgumentException("No attribute for object id - " + oid.getId() + " - passed to distinguished name");            }            this.values.addElement(attributes.get(oid)); // copy the hash table        }    }    /**     * Takes two vectors one of the oids and the other of the values.     */    public X509Name(        Vector  oids,        Vector  values)    {        this(oids, values, new X509DefaultEntryConverter());    }    /**     * Takes two vectors one of the oids and the other of the values.     * <p>     * The passed in converter will be used to convert the strings into their     * ASN.1 counterparts.     */    public X509Name(        Vector                  oids,        Vector                  values,        X509NameEntryConverter  converter)    {        this.converter = 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.ordering.addElement(oids.elementAt(i));            this.values.addElement(values.elementAt(i));            this.added.addElement(FALSE);        }    }//    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.     */    public X509Name(        String  dirName)    {        this(DefaultReverse, DefaultLookUp, 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.     */    public X509Name(        String                  dirName,        X509NameEntryConverter  converter)    {        this(DefaultReverse, DefaultLookUp, dirName, converter);    }    /**     * 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.     */    public X509Name(        boolean reverse,        String  dirName)    {        this(reverse, DefaultLookUp, 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. 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.     */    public X509Name(        boolean                 reverse,        String                  dirName,        X509NameEntryConverter  converter)    {        this(reverse, DefaultLookUp, dirName, converter);    }    /**     * 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.     * <br>     * If reverse is true, create the encoded version of the sequence     * starting from the last element in the string.     * @param reverse true if we should start scanning from the end (RFC 2553).     * @param lookUp table of names and their oids.     * @param dirName the X.500 string to be parsed.     */    public X509Name(        boolean     reverse,        Hashtable   lookUp,        String      dirName)    {        this(reverse, lookUp, dirName, new X509DefaultEntryConverter());    }    private DERObjectIdentifier decodeOID(        String      name,        Hashtable   lookUp)    {        if (Strings.toUpperCase(name).startsWith("OID."))        {            return new DERObjectIdentifier(name.substring(4));        }        else if (name.charAt(0) >= '0' && name.charAt(0) <= '9')        {            return new DERObjectIdentifier(name);        }        DERObjectIdentifier oid = (DERObjectIdentifier)lookUp.get(Strings.toLowerCase(name));        if (oid == null)        {            throw new IllegalArgumentException("Unknown object id - " + name + " - passed to distinguished name");        }        return oid;    }    /**     * 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. The passed in converter is used to convert the     * string values to the right of each equals sign to their ASN.1 counterparts.     * <br>     * @param reverse true if we should start scanning from the end, false otherwise.     * @param lookUp table of names and oids.     * @param dirName the string dirName     * @param converter the converter to convert string values into their ASN.1 equivalents     */    public X509Name(        boolean                 reverse,        Hashtable               lookUp,        String                  dirName,        X509NameEntryConverter  converter)    {        this.converter = converter;        X509NameTokenizer   nTok = new X509NameTokenizer(dirName);        while (nTok.hasMoreTokens())        {            String  token = nTok.nextToken();            int     index = token.indexOf('=');            if (index == -1)            {                throw new IllegalArgumentException("badly formated directory string");            }            String              name = token.substring(0, index);            String              value = token.substring(index + 1);            DERObjectIdentifier oid = decodeOID(name, lookUp);            if (value.indexOf('+') > 0)            {                X509NameTokenizer   vTok = new X509NameTokenizer(value, '+');                String  v = vTok.nextToken();                this.ordering.addElement(oid);                this.values.addElement(v);                this.added.addElement(FALSE);                while (vTok.hasMoreTokens())                {                    String  sv = vTok.nextToken();                    int     ndx = sv.indexOf('=');                    String  nm = sv.substring(0, ndx);                    String  vl = sv.substring(ndx + 1);                    this.ordering.addElement(decodeOID(nm, lookUp));                    this.values.addElement(vl);                    this.added.addElement(TRUE);                }            }            else            {                this.ordering.addElement(oid);                this.values.addElement(value);                this.added.addElement(FALSE);            }        }        if (reverse)        {            Vector  o = new Vector();            Vector  v = new Vector();            Vector  a = new Vector();            int count = 1;            for (int i = 0; i < this.ordering.size(); i++)            {                if (((Boolean)this.added.elementAt(i)).booleanValue())                {                    o.insertElementAt(this.ordering.elementAt(i), count);                    v.insertElementAt(this.values.elementAt(i), count);                    a.insertElementAt(this.added.elementAt(i), count);                    count++;                }                else                {                    o.insertElementAt(this.ordering.elementAt(i), 0);                    v.insertElementAt(this.values.elementAt(i), 0);                    a.insertElementAt(this.added.elementAt(i), 0);                    count = 1;                }            }            this.ordering = o;            this.values = v;            this.added = a;        }    }    /**     * 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 != ordering.size(); i++)        {            v.addElement(ordering.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 != values.size(); i++)        {            v.addElement(values.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(        DERObjectIdentifier oid)    {        Vector  v = new Vector();        for (int i = 0; i != values.size(); i++)        {            if (ordering.elementAt(i).equals(oid))            {                String val = (String)values.elementAt(i);                if (val.length() > 2 && val.charAt(0) == '\\' && val.charAt(1) == '#')                {                    v.addElement(val.substring(1));                }                else                {                    v.addElement(val);                }            }        }        return v;    }    public DERObject toASN1Object()    {        if (seq == null)        {            ASN1EncodableVector  vec = new ASN1EncodableVector();            ASN1EncodableVector  sVec = new ASN1EncodableVector();            DERObjectIdentifier  lstOid = null;                        for (int i = 0; i != ordering.size(); i++)            {                ASN1EncodableVector     v = new ASN1EncodableVector();                DERObjectIdentifier     oid = (DERObjectIdentifier)ordering.elementAt(i);                v.add(oid);                String  str = (String)values.elementAt(i);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -