public final class X500Principal extends Object implements Principal, Serializable
This class represents an X.500 Principal
. X500Principal
s are represented by distinguished
names such as "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US".
This class can be instantiated by using a string representation of the distinguished name, or by using the ASN.1 DER encoded byte representation of the distinguished name. The current specification for the string representation of a distinguished name is defined in RFC 2253: Lightweight Directory Access Protocol (v3): UTF-8 String Representation of Distinguished Names. This class, however, accepts string formats from both RFC 2253 and RFC 1779: A String Representation of Distinguished Names, and also recognizes attribute type keywords whose OIDs (Object Identifiers) are defined in RFC 3280: Internet X.509 Public Key Infrastructure Certificate and CRL Profile.
The string representation for this X500Principal
can be obtained by calling the getName
methods.
Note that the getSubjectX500Principal
and getIssuerX500Principal
methods of
X509Certificate
return X500Principals representing the issuer and subject fields of the certificate.
X509Certificate
,
Serialized FormConstructor and Description |
---|
X500Principal(byte[] name)
Creates an
X500Principal from a distinguished name in ASN.1 DER encoded form. |
X500Principal(InputStream is)
Creates an
X500Principal from an InputStream containing the distinguished name in ASN.1
DER encoded form. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Compares the specified
Object with this X500Principal for equality. |
String |
getName()
Returns a string representation of the X.500 distinguished name.
|
int |
hashCode()
Return a hash code for this
X500Principal . |
String |
toString()
Return a user-friendly string representation of this
X500Principal . |
public X500Principal(byte[] name)
X500Principal
from a distinguished name in ASN.1 DER encoded form. The ASN.1 notation for
this structure is as follows.
Name ::= CHOICE {
RDNSequence }
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
RelativeDistinguishedName ::=
SET SIZE (1 .. MAX) OF AttributeTypeAndValue
AttributeTypeAndValue ::= SEQUENCE {
type AttributeType,
value AttributeValue }
AttributeType ::= OBJECT IDENTIFIER
AttributeValue ::= ANY DEFINED BY AttributeType
....
DirectoryString ::= CHOICE {
teletexString TeletexString (SIZE (1..MAX)),
printableString PrintableString (SIZE (1..MAX)),
universalString UniversalString (SIZE (1..MAX)),
utf8String UTF8String (SIZE (1.. MAX)),
bmpString BMPString (SIZE (1..MAX)) }
name
- a byte array containing the distinguished name in ASN.1 DER encoded formIllegalArgumentException
- if an encoding error occurs (incorrect form for DN)public X500Principal(InputStream is)
X500Principal
from an InputStream
containing the distinguished name in ASN.1
DER encoded form. The ASN.1 notation for this structure is supplied in the documentation for
X500Principal(byte[] name)
.
The read position of the input stream is positioned to the next available byte after the encoded distinguished name.
is
- an InputStream
containing the distinguished name in ASN.1 DER encoded formNullPointerException
- if the InputStream
is null
IllegalArgumentException
- if an encoding error occurs (incorrect form for DN)public String getName()
The chosen format is a '#' character followed by the hexadecimal encoding of de DER representation of the name. (No spaces between digits, letters in lower case).
X500Principal
public String toString()
X500Principal
.
In MicroEJ's implementation, the chosen format is RFC.public boolean equals(@Nullable Object o)
Object
with this X500Principal
for equality.
Specifically, this method returns true
if the Object
o is an
X500Principal
and if the respective canonical string representations (obtained via the
getName(X500Principal.CANONICAL)
method) of this object and o are equal.
This implementation is compliant with the requirements of RFC 3280.
public int hashCode()
X500Principal
.
The hash code is calculated via: getName(X500Principal.CANONICAL).hashCode()
hashCode
in interface Principal
hashCode
in class Object
X500Principal
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)