codec.x509
Class SubjectPublicKeyInfo

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.ArrayList
                    |
                    +--codec.asn1.ASN1AbstractCollection
                          |
                          +--codec.asn1.ASN1Sequence
                                |
                                +--codec.x509.SubjectPublicKeyInfo
All Implemented Interfaces:
ASN1Collection, ASN1Type, Cloneable, Collection, Externalizable, List, Serializable

public class SubjectPublicKeyInfo
extends ASN1Sequence

Subject Public Key Info according to RFC2459. Consists of an AlgorithmID and the corresponding public key

 SubjectPublicKeyInfo  ::=  SEQUENCE  {
   algorithm            AlgorithmIdentifier,
   subjectPublicKey     BIT STRING
 }
 
Raw public key material embedded in this structure need not be ASN.1/DER encoded. Some crypto systems such as elliptic curve systems use specific encodings of keys. For this reason, keys can be retrieved by means of two alternative ways: Only ASN.1/DER is supported as decoding method. Keys encoded in another code must be decoded externally. Creation date: (18.08.99 15:23:09)

Version:
"$Id: SubjectPublicKeyInfo.java,v 1.3 2004/08/16 08:53:58 pebinger Exp $"
Author:
Markus Tak
See Also:
Serialized Form

Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SubjectPublicKeyInfo()
          Creates an instance that is ready for decoding.
SubjectPublicKeyInfo(AlgorithmIdentifier aid, ASN1Type key)
          Creates an instance with the given AlgorithmIdentifier and key.
SubjectPublicKeyInfo(AlgorithmIdentifier aid, byte[] key)
          Creates an instance with the given AlgorithmIdentifier and encoded public key.
SubjectPublicKeyInfo(PublicKey key)
          Creates an instance that is initialized from the given public key.
 
Method Summary
 AlgorithmIdentifier getAlgorithmIdentifier()
          Returns the AlgorithmIdentifier of the public key.
 ASN1Type getDecodedRawKey()
          Returns an ASN.1 type that represents the decoded raw key.
 ASN1Type getKeyStruct()
          Deprecated. This method is no longer used.
 ASN1Type getKeyStruct(boolean derDecode)
          Deprecated. This method is no longer used.
 PublicKey getPublicKey()
          Returns the public key embedded in this structure.
 byte[] getRawKey()
          Returns the raw key material.
 void setAlgorithmIdentifier(AlgorithmIdentifier aid)
          sets the AlgorithmIdentifier for this public key
 void setKeyStruct(ASN1Type key)
          Deprecated. This method is no longer used.
 void setPublicKey(PublicKey key)
          Initializes this instance with the given public key.
protected  void setRawKey(ASN1Type key)
          Encodes and sets the given ASN.1 key structure as the raw key.
 
Methods inherited from class codec.asn1.ASN1Sequence
getTag
 
Methods inherited from class codec.asn1.ASN1AbstractCollection
checkConstraints, decode, encode, getCollection, getConstraint, getTagClass, getValue, isExplicit, isOptional, isType, readExternal, setConstraint, setExplicit, setOptional, toString, writeExternal
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Constructor Detail

SubjectPublicKeyInfo

public SubjectPublicKeyInfo()
Creates an instance that is ready for decoding.

SubjectPublicKeyInfo

public SubjectPublicKeyInfo(AlgorithmIdentifier aid,
                            byte[] key)
Creates an instance with the given AlgorithmIdentifier and encoded public key. The public key is wrapped into an ASN1BitString as required by the specification of this structure. Hence, the encoded key is taken "as is".

The given arguments are put into this instance literally. The arguments are not copied or cloned. Therefor side effects can occur when the given arguments are modified after this constructor was called.

Parameters:
aid - AlgorithmIdentifier of the public key algorithm
key - The encoded key material.
Throws:
NullPointerException - if either argument is null.

SubjectPublicKeyInfo

public SubjectPublicKeyInfo(AlgorithmIdentifier aid,
                            ASN1Type key)
Creates an instance with the given AlgorithmIdentifier and key. The given key must be a raw key structure represented by means of an ASN.1 structure. The key structure is encoded into a bit string which is put into this instance.
Parameters:
aid - The AlgorithmIdentifier of the public key algorithm.
key - The public key as a ASN.1 data structure.

SubjectPublicKeyInfo

public SubjectPublicKeyInfo(PublicKey key)
                     throws InvalidKeyException
Creates an instance that is initialized from the given public key.
Parameters:
key - The public key.
Throws:
InvalidKeyException - if the key cannot be decoded properly.
NullPointerException - if the given key is null.
Method Detail

getPublicKey

public PublicKey getPublicKey()
                       throws NoSuchAlgorithmException
Returns the public key embedded in this structure.

This method creates an X509EncodedKeySpec of this instance and feeds it into a key factory. In order to locate a suitable key factory, the installed providers must define appropriate OID mappings.

Returns:
The public key.
Throws:
InconsistentStateException - if the key spec generated by this method is rejected by the key factory that is used to generate the key.
NoSuchAlgorithmException - if there is no key factory registered for the algorithm of the embedded key or no appropriate OID mapping is defined by the installed providers.

setPublicKey

public void setPublicKey(PublicKey key)
                  throws InvalidKeyException
Initializes this instance with the given public key.
Parameters:
key - The public key from which this instance is initialized.
Throws:
InvalidKeyException - if the given key cannot be decoded properly.
NullPointerException - if the given key is null.

setRawKey

protected void setRawKey(ASN1Type key)
Encodes and sets the given ASN.1 key structure as the raw key.
Throws:
InconsistentStateException - if an internal error occurs while the key is encoded. This should never happen.

getRawKey

public byte[] getRawKey()
Returns the raw key material. The key material consists of an encoded key structure. ASN.1/DER is often used as the encoding. However, this need not always be the case. Elliptic curve cryptosystems use specific encodings.

If the key encoding is ASN.1/DER then the raw key can be retrieved as an ASN.1 type by means of the getDecodedRawKey() method.

Returns:
The raw key bytes as a byte array.

getDecodedRawKey

public ASN1Type getDecodedRawKey()
                          throws CorruptedCodeException
Returns an ASN.1 type that represents the decoded raw key. Decoding is done by means of ASN.1/DER. Be careful, not all public keys are encoded according to DER. Elliptic curve cryptosystems use specific encodings.
Returns:
The raw key decoded according to DER.

getAlgorithmIdentifier

public AlgorithmIdentifier getAlgorithmIdentifier()
Returns the AlgorithmIdentifier of the public key.
Returns:
The key algorithm's AlgorithmIdentifier.

setAlgorithmIdentifier

public void setAlgorithmIdentifier(AlgorithmIdentifier aid)
sets the AlgorithmIdentifier for this public key
Parameters:
aid - AlgorithmIdentifier of this public key

getKeyStruct

public ASN1Type getKeyStruct()
                      throws CorruptedCodeException
Deprecated. This method is no longer used.


getKeyStruct

public ASN1Type getKeyStruct(boolean derDecode)
                      throws CorruptedCodeException
Deprecated. This method is no longer used.

Parameters:
derDecode - true if the raw key shall be decoded.

setKeyStruct

public void setKeyStruct(ASN1Type key)
Deprecated. This method is no longer used.

Parameters:
key - The key structure.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.