All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sun.security.x509.X509Key

java.lang.Object
   |
   +----sun.security.x509.X509Key

public class X509Key
extends Object
implements PublicKey
Holds an X.509 key, for example a public key found in an X.509 certificate. Includes a description of the algorithm to be used with the key; these keys normally are used as "SubjectPublicKeyInfo".

While this class can represent any kind of X.509 key, it may be desirable to provide subclasses which understand how to parse keying data. For example, RSA public keys have two members, one for the public modulus and one for the prime exponent. If such a class is provided, it is used when parsing X.509 keys. If one is not provided, the key still parses correctly.


Variable Index

 o algid
 o key

Constructor Index

 o X509Key()
Default constructor.

Method Index

 o decode(byte[])
 o decode(InputStream)
Initialize an X509Key object from an input stream.
 o emit(DerOutputStream)
Emit SubjectPublicKeyInfo sequence on the DER output stream.
 o encode()
Returns the DER-encoded form of the key as a byte array.
 o equals(Object)
Compares two Objects for equality.
 o getAlgorithm()
Returns the algorithm to be used with this key.
 o getAlgorithmId()
Returns the algorithm ID to be used with this key.
 o getEncoded()
Returns the DER-encoded form of the key as a byte array.
 o getFormat()
Returns the format for this key: "X.509"
 o parse(DerValue)
Construct X.509 subject public key from a DER value.
 o parseKeyBits()
Parse the key bits.
 o toString()
Returns a string representation of the object.

Variables

 o algid
 protected AlgorithmId algid
 o key
 protected byte key[]

Constructors

 o X509Key
 protected X509Key()
Default constructor. The key constructed must have its key and algorithm initialized before it may be used, for example by using decode.

Methods

 o parse
 public static X509Key parse(DerValue in) throws IOException
Construct X.509 subject public key from a DER value. If the runtime environment is configured with a specific class for this kind of key, a subclass is returned. Otherwise, a generic X509Key object is returned.

This mechanism gurantees that keys (and algorithms) may be freely manipulated and transferred, without risk of losing information. Also, when a key (or algorithm) needs some special handling, that specific need can be accomodated.

Parameters:
in - the DER-encoded SubjectPublicKeyInfo value
Throws: IOException
on data format errors
 o parseKeyBits
 protected void parseKeyBits() throws IOException, InvalidKeyException
Parse the key bits. This may be redefined by subclasses to take advantage of structure within the key. For example, RSA public keys encapsulate two unsigned integers (modulus and exponent) as DER values within the key bits; Diffie-Hellman and DSS/DSA keys encapsulate a single unsigned integer.

This function is called when creating X.509 SubjectPublicKeyInfo values using the X509Key member functions, such as parse and decode.

 o getAlgorithm
 public String getAlgorithm()
Returns the algorithm to be used with this key.

 o getAlgorithmId
 public AlgorithmId getAlgorithmId()
Returns the algorithm ID to be used with this key.

 o emit
 public final void emit(DerOutputStream out) throws IOException
Emit SubjectPublicKeyInfo sequence on the DER output stream.

 o getEncoded
 public synchronized byte[] getEncoded()
Returns the DER-encoded form of the key as a byte array.

 o getFormat
 public String getFormat()
Returns the format for this key: "X.509"

 o encode
 public byte[] encode() throws InvalidKeyException
Returns the DER-encoded form of the key as a byte array.

 o toString
 public String toString()
Returns a string representation of the object.

Overrides:
toString in class Object
 o decode
 public void decode(InputStream in) throws InvalidKeyException
Initialize an X509Key object from an input stream. The data on that input stream must be encoded using DER, obeying the X.509 SubjectPublicKeyInfo format. That is, the data is a sequence consisting of an algorithm ID and a bit string which holds the key. (That bit string is often used to encapsulate another DER encoded sequence.)

Subclasses should not normally redefine this method; they should instead provide a parseKeyBits method to parse any fields inside the key member.

The exception to this rule is that since private keys need not be encoded using the X.509 SubjectPublicKeyInfo format, private keys may override this method, encode, and of course getFormat.

Parameters:
in - an input stream with a DER-encoded X.509 SubjectPublicKeyInfo value
 o decode
 public void decode(byte encodedKey[]) throws InvalidKeyException
 o equals
 public boolean equals(Object object)
Compares two Objects for equality.

Overrides:
equals in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index