codec.x509
Class AlgorithmIdentifier

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

public class AlgorithmIdentifier
extends ASN1Sequence

This class represents the ASN.1/DER value of the AlgorithmIdentifier defined in Annex D to Recommendation X.509. This structure is extensively used for instance in the PKCS standards of RSA Inc. The ASN.1 definition of this structure is as given below:

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

For this class to work properly, providers need to define the following algorithm aliases for the AlgorithmParameters implementations they provide:

  1. AlgorithmParameters.MyAlg = class
  2. Alg.Alias.AlgorithmParameters.1.2.3.4 = MyAlg
  3. Alg.Alias.AlgorithmParameters.OID.1.2.3.4 = MyAlg
The first property defined the mapping of the JCE compliant standard name of the algorithm to the implementing class. The second provider entry allows mapping OID to those algorithm names while the third allows mapping those names on corresponding OID.

The alias definitions are used by this class in order to find an AlgorithmParameters implementation for the OID embedded in the X.509 AlgorithmIdentifier structure, and to create the OID for a given AlgorithmParameters instances. This is done by means of the JCA class, which operates on the engine and alias definitions of the installed providers.

Version:
"$Id: AlgorithmIdentifier.java,v 1.3 2004/08/13 11:37:03 pebinger Exp $"
Author:
Volker Roth
See Also:
JCA, Serialized Form

Field Summary
protected  ASN1ObjectIdentifier algorithm_
          The OID of the algorithm.
protected  ASN1Opaque parameters_
          The algorithm parameters of the algorithm specified by this algorithm identifier.
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
AlgorithmIdentifier()
          This method builds the tree of ASN.1 objects used for decoding this structure.
AlgorithmIdentifier(ASN1ObjectIdentifier oid, ASN1Type params)
          Creates an instance with the given OID and parameters.
AlgorithmIdentifier(ASN1ObjectIdentifier oid, byte[] b)
          Creates an instance with the given OID and opaque algorithm parameter representation.
AlgorithmIdentifier(String algorithm)
          Creates an instance initialized to the given algorithm.
AlgorithmIdentifier(String alg, AlgorithmParameters params)
          Creates an instance that is initialized from the given AlgorithmParameters instance.
 
Method Summary
 Object clone()
          Returns a clone.
static AlgorithmIdentifier createAlgorithmIdentifier(Key key)
          Creates an AlgorithmIdentifier from the given key.
 boolean equals(Object o)
          This method returns true if the given object is an instance of this class or a subclass thereof and the algorithm OID of the given object equals this object's algorithm OID.
 String getAlgorithmName()
          This method returns the JCE standard name of the algorithm specified in this AlgorithmIdentifier.
 ASN1ObjectIdentifier getAlgorithmOID()
          This method returns the OID of the algorithm represented by this AlgorithmIdentifier.
 AlgorithmParameters getParameters()
          This method locates a suitable AlgorithmParameters implementation if it is available from the JCE compliant security providers that are installed locally.
 int hashCode()
           
 String toString()
          Returns a string representation of this object.
 
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, writeExternal
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
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, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface java.util.List
containsAll, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Field Detail

parameters_

protected ASN1Opaque parameters_
The algorithm parameters of the algorithm specified by this algorithm identifier.

algorithm_

protected ASN1ObjectIdentifier algorithm_
The OID of the algorithm.
Constructor Detail

AlgorithmIdentifier

public AlgorithmIdentifier()
This method builds the tree of ASN.1 objects used for decoding this structure.

AlgorithmIdentifier

public AlgorithmIdentifier(String algorithm)
                    throws NoSuchAlgorithmException
Creates an instance initialized to the given algorithm. The algorithm must not have parameters since this constructor does not take a parameter argument.
Parameters:
algorithm - The JCE standard algorithm name.
Throws:
NoSuchAlgorithmException - if the name cannot be resolved to an OID or the OID has a bad syntax.
NullPointerException - if algorithm is null.

AlgorithmIdentifier

public AlgorithmIdentifier(ASN1ObjectIdentifier oid,
                           byte[] b)
                    throws ASN1Exception
Creates an instance with the given OID and opaque algorithm parameter representation. Both the given OID and the parameter encoding is cloned or copied. No side effects occur if these arguments are modified after completition of this constructor.
Parameters:
oid - The algorithm object identifier.
b - The opaque DER encoding of the parameters for the algorithm known under the given OID. If no parameters are required then null might be passed. In that case ASN.1 NULL is encoded.
Throws:
ASN1Exception - if the opaque representation does not contain a valid DER header and contents octets.

AlgorithmIdentifier

public AlgorithmIdentifier(String alg,
                           AlgorithmParameters params)
                    throws InvalidAlgorithmParameterException
Creates an instance that is initialized from the given AlgorithmParameters instance. This method attempts to map the algorithm name to an ASN.1 OID by calling JCA#getOID.

Parameters:
alg - The name of the algorithm.
params - The AlgorithmParameters.
Throws:
NullPointerException - if alg is null.
InvalidAlgorithmParameterException - if the given parameters have a bad encoding, or the OID of the algorithm cannot be determined.

AlgorithmIdentifier

public AlgorithmIdentifier(ASN1ObjectIdentifier oid,
                           ASN1Type params)
                    throws ASN1Exception
Creates an instance with the given OID and parameters. The parameters are encoded according to DER and stored by means of an opaque type. If the given parameters are null then an ASN.1 NULL is encoded.
Parameters:
oid - The OID to use.
params - The ASN.1 type of which the parameters consist.
Throws:
InconsistentStateException - if an internal error occurs; this should never happen.
ASN1Exception - if the given parameters cannot be encoded. This should rarely happen.
Method Detail

createAlgorithmIdentifier

public static AlgorithmIdentifier createAlgorithmIdentifier(Key key)
                                                     throws CorruptedCodeException
Creates an AlgorithmIdentifier from the given key. The key must be either a public key or a private key. No secret (symmetric) keys are accepted.

The keys encoding must be either a a PrivateKeyInfo or a SubjectPublicKeyInfo.

Parameters:
key - The key from which the AlgorithmIdentifier shall be extracted.
Throws:
IllegalArgumentException - if the given key is neither a PublicKey or a PrivateKey.
CorruptedCodeException - if an exception was caught while decoding the key's encoding.

getParameters

public AlgorithmParameters getParameters()
                                  throws NoSuchAlgorithmException,
                                         InvalidAlgorithmParameterException
This method locates a suitable AlgorithmParameters implementation if it is available from the JCE compliant security providers that are installed locally.

Such providers need to specify the following aliases for this to work:

If you ever want to test a provider for compliance with the JCE and cleverness, test it against the FhG-IGD PKCS package. If it doesn't work then better demand fixes from the provider's vendor.

This method may be called only if this instance is initialized properly either by specifying AlgorithmParameters in a constructor or by parsing a valid ASN.1/DER encoding.

Returns:
The AlgorithmParameters or null if none are enclosed in this structure.
Throws:
NoSuchAlgorithmException - if no matching AlgorithmParameters engine is found.
InvalidAlgorithmParameterException - if the parameters cannot be decoded properly.

getAlgorithmOID

public ASN1ObjectIdentifier getAlgorithmOID()
This method returns the OID of the algorithm represented by this AlgorithmIdentifier. The OID returned is the one used internally. Do not modify the returned OID! Otherwise, side effects occur.
Returns:
The algorithm OID.

getAlgorithmName

public String getAlgorithmName()
This method returns the JCE standard name of the algorithm specified in this AlgorithmIdentifier. However, for this to work a proper alias for the algorithm must be defined by some provider. See the general documentation of this class for details on that.

This method calls JCA.getName() with the string representation of this instance's object identifier.

If you are retrieving the parameters anyway then avoid calling this method and call getAlgorithm on the parameter instance instead.


toString

public String toString()
Returns a string representation of this object.
Overrides:
toString in class ASN1AbstractCollection
Returns:
The string representation.

equals

public boolean equals(Object o)
This method returns true if the given object is an instance of this class or a subclass thereof and the algorithm OID of the given object equals this object's algorithm OID.
Overrides:
equals in class AbstractList
Returns:
true if the given object equals this one.

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractList

clone

public Object clone()
Returns a clone. The clone is a deep copy of this instance except from the constraints. Constraints are copied by reference.
Overrides:
clone in class ArrayList
Returns:
The clone.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.