iaik.x509
Class PublicKeyInfo

java.lang.Object
  |
  +--iaik.x509.PublicKeyInfo
All Implemented Interfaces:
ASN1Type, Cloneable, Key, PublicKey, Serializable
Direct Known Subclasses:
DHPublicKey, DSAPublicKey, ESDHPublicKey, RSAPublicKey

public abstract class PublicKeyInfo
extends Object
implements ASN1Type, Serializable, PublicKey, Cloneable

This class implements a PublicKeyInfo as used within X.509 certificates for representing the subject´s public key in the SubjectPublicKeyInfo field. The subject is the entity claiming for certification of its public key. The subject´s public key is of type subjectPublicKeyInfo including a BIT-STRING representation of the public key together with an identification of the public-key algorithm being used, as defined in RFC 2459:

 SubjectPublicKeyInfo  ::=  SEQUENCE  {
   algorithm            AlgorithmIdentifier,
   subjectPublicKey     BIT STRING  }
 

where:

 AlgorithmIdentifier  ::=  SEQUENCE  {
   algorithm               OBJECT IDENTIFIER,
   parameters              ANY DEFINED BY algorithm OPTIONAL  }

 

This class has to be extended by any class implementing some particular public key (e.g. RSAPublicKey, DSAPublicKey, DHPublicKey) for being used within the X.509 certificate environment.

This class provides a variety of methods for creating, parsing, de- and encoding public key informations.

As an example, for creating an instance of java.security.PublicKey from an ASN1Object representation, or a DER encoding, use the static getPublicKey(ASN1Object) respectively getPublicKey(byte[]) methods, e.g.:

 byte[] encoding = ...;
 PublicKey publicKey = PublicKeyInfo(encoding);
 

Version:
File Revision 23
See Also:
X509Certificate, RSAPublicKey, DSAPublicKey, DHPublicKey, AlgorithmID, Serialized Form

Field Summary
protected  AlgorithmID public_key_algorithm
          The algorithm identifier of the public key algorithm belonging to the particular public key implemeting this PublicKeyInfo.
 
Fields inherited from interface java.security.PublicKey
serialVersionUID
 
Constructor Summary
protected PublicKeyInfo()
          Default Constructor for derived classes.
  PublicKeyInfo(ASN1Object obj)
          Creates a new PublicKeyInfo from an ASN1Object.
  PublicKeyInfo(byte[] arr)
          Creates a new PublicKeyInfo from a DER byte array.
  PublicKeyInfo(InputStream is)
          Creates a new PublicKeyInfo from an InputStream.
 
Method Summary
 Object clone()
          Return a clone of this private key object.
protected  void createPublicKeyInfo()
          Creates a PublicKeyInfo data structure (X.509).
 void decode(ASN1Object obj)
          Decodes the given ASN.1 PublicKeyInfo object for parsing the internal structure.
protected abstract  void decode(byte[] publicKey)
          Abstract method to be implemented for decoding a DER encoded public key.
protected abstract  byte[] encode()
          Abstract method to be implemented for DER encoding the particular public key extending this PublicKeyInfo.
 boolean equals(Object obj)
          Compares this public key to another public key.
abstract  String getAlgorithm()
          Returns the name of the appertaining algorithm.
 byte[] getEncoded()
          Returns this PublicKeyInfo as a DER encoded ASN.1 data structure.
 byte[] getFingerprint()
          Returns a fingerprint of the public key.
 String getFormat()
          Returns the name of the encoding format.
static PublicKey getPublicKey(ASN1Object publicKey)
          Creates a PublicKey from an ASN1Object.
static PublicKey getPublicKey(byte[] publicKeyInfo)
          Creates a PublicKey from a DER encoded byte array.
 int hashCode()
          Returns a hash code for this object.
 ASN1Object toASN1Object()
          Returns this PublicKeyInfo as ASN1Object.
 String toString()
          Returns a string that represents the contents of this public key.
 void writeTo(OutputStream os)
          Writes this public key to an output stream.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

public_key_algorithm

protected AlgorithmID public_key_algorithm
The algorithm identifier of the public key algorithm belonging to the particular public key implemeting this PublicKeyInfo.
Constructor Detail

PublicKeyInfo

protected PublicKeyInfo()
Default Constructor for derived classes.

PublicKeyInfo

public PublicKeyInfo(ASN1Object obj)
              throws InvalidKeyException
Creates a new PublicKeyInfo from an ASN1Object.

This constructor may be used for parsing an already exisiting PublicKeyInfo object, supplied as ASN1Object that may have been created by calling toASN1Object.

Parameters:
obj - the PublicKeyInfo as ASN1Object
Throws:
InvalidKeyException - if the data can not be parsed

PublicKeyInfo

public PublicKeyInfo(InputStream is)
              throws InvalidKeyException,
                     IOException
Creates a new PublicKeyInfo from an InputStream.

This constructor reads a DER or PEM encoded PublicKeyInfo which previously may have been written with method writeTo(OutputStream). This constructor cannot be used to read a serialized object.

Parameters:
is - the input stream from where the encoded PublicKeyInfo shall be read
Throws:
InvalidKeyException - if the data can not be parsed
IOException - if an I/O error occurs

PublicKeyInfo

public PublicKeyInfo(byte[] arr)
              throws InvalidKeyException
Creates a new PublicKeyInfo from a DER byte array.

This constructor may be used for parsing an already exisiting PublicKeyInfo ASN1 object, supplied as DER encoded byte array, which may have been created by calling the getEncoded method.

Parameters:
arr - the array containing the encoded PublicKeyInfo
Throws:
InvalidKeyException - if the data can not be parsed
Method Detail

decode

protected abstract void decode(byte[] publicKey)
                        throws InvalidKeyException
Abstract method to be implemented for decoding a DER encoded public key.
Parameters:
publicKey - the public key as DER encoded ASN.1 object
Throws:
InvalidKeyException - if something is wrong with the encoding of the key

encode

protected abstract byte[] encode()
Abstract method to be implemented for DER encoding the particular public key extending this PublicKeyInfo.
Returns:
a byte array holding the public key implementation as a DER encoded ASN.1 datastructure

getAlgorithm

public abstract String getAlgorithm()
Returns the name of the appertaining algorithm.
Specified by:
getAlgorithm in interface Key
Returns:
the name of the algorithm

clone

public Object clone()
Return a clone of this private key object.
Overrides:
clone in class Object
Returns:
A clone of this private key object.

decode

public void decode(ASN1Object obj)
            throws CodingException
Decodes the given ASN.1 PublicKeyInfo object for parsing the internal structure.

This method implements the ASN1Type interface.

Specified by:
decode in interface ASN1Type
Parameters:
obj - the PublicKeyInfo as ASN1Object
Throws:
CodingException - if the ASN1Object could not be parsed

createPublicKeyInfo

protected void createPublicKeyInfo()
Creates a PublicKeyInfo data structure (X.509).

This method is called by extending classes for creating a PublicKeyInfo. This method creates a PublicKeyInfo as an ASN.1 SEQUENCE object with components as specified in RFC 2459:

 SubjectPublicKeyInfo ::=  SEQUENCE  {
   algorithm            AlgorithmIdentifier,
   subjectPublicKey     BIT STRING  }
 


getPublicKey

public static PublicKey getPublicKey(ASN1Object publicKey)
                              throws InvalidKeyException
Creates a PublicKey from an ASN1Object.

This is a static method and therefore may be called for creating a PublicKeyInfo from the given ASN1Object without explicitly instantiating this class, e.g:

 PublicKey pub_ki = PublicKeyInfo.getPublicKey(asn1_obj);
 

The given ASN1Object represents an already exisiting PrublicKeyInfo object, and may have been created by calling toASN1Object.

Parameters:
publicKey - the PublicKey as ASN1Object
Returns:
an instance of java.security.PublicKey, parsed from the supplied ASN1Object
Throws:
InvalidKeyException - if the ASN1Object cannot be parsed or the inherent AlgorithmID does not match to any implemented public-key algorithm

getPublicKey

public static PublicKey getPublicKey(byte[] publicKeyInfo)
                              throws InvalidKeyException
Creates a PublicKey from a DER encoded byte array.

This is a static method and therefore may be called for creating a PublicKeyInfo from the given DER encoded ASN1Object without explicitly instantiating this class, e.g:

 PublicKey pub_key = PublicKeyInfo.getPublicKey(key_array);
 

The given DER encoded ASN1Object represents an already exisiting PublicKeyInfo object, and may have been created by calling getEncoded.

Parameters:
publicKeyInfo - the PublicKey as DER encoded byte array
Returns:
an instance of java.security.PublicKey, parsed from the supplied DER encoding
Throws:
InvalidKeyException - if the publicKeyInfo cannot be parsed

toASN1Object

public ASN1Object toASN1Object()
Returns this PublicKeyInfo as ASN1Object.
Specified by:
toASN1Object in interface ASN1Type
Returns:
this PublicKeyInfo as ASN1Object

equals

public boolean equals(Object obj)
Compares this public key to another public key. This method simply compares der DER encoded version of the keys.
Overrides:
equals in class Object
Returns:
true, if the 2 public keys are equal, false otherwise

hashCode

public int hashCode()
Returns a hash code for this object.
Overrides:
hashCode in class Object
Returns:
the hash code

getEncoded

public byte[] getEncoded()
Returns this PublicKeyInfo as a DER encoded ASN.1 data structure.
Specified by:
getEncoded in interface Key
Returns:
this PublicKeyInfo as DER encoded byte array

getFormat

public String getFormat()
Returns the name of the encoding format.
Specified by:
getFormat in interface Key
Returns:
the string "X.509"

getFingerprint

public byte[] getFingerprint()
Returns a fingerprint of the public key. This method only computes a MD5 hash over the DER encoded public key.
Returns:
a fingerprint of the public key

writeTo

public void writeTo(OutputStream os)
             throws IOException
Writes this public key to an output stream.
Parameters:
os - the output stream
Throws:
IOException - if an I/O error occurs

toString

public String toString()
Returns a string that represents the contents of this public key.
Overrides:
toString in class Object
Returns:
the string representation

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK