iaik.security.dsa
Class DSAPublicKey

java.lang.Object
  |
  +--iaik.x509.PublicKeyInfo
        |
        +--iaik.security.dsa.DSAPublicKey

public class DSAPublicKey
extends PublicKeyInfo
implements DSAPublicKey, java.io.Serializable

An implementation of a DSA public key that supports ASN.1 encoding.

This class extends iaik.x509.PublicKeyInfo for supporting DSA public keys to be used within X.509 certificates . This class implements the java.security.interfaces.DSAPublicKey interface for providing the functionality of a public key used for verifying some signature within the DSA algorithm.

The Digital Signature Algorithm (DSA) only can be used for digital signing (respectively signature verifying). It cannot be used for data encryption.

The DSA algorithm uses a certain number of parameters:

p, q, g are made public, y forms the public key, and x represents the private key. The procedures of signing some message with one entity´s private key, and verifying a signature using the signer´s public key may be read up in "Applied Cryptography", Bruce Schneier, ISBN 0-471-59756-2).

An application wishing to create a DSAPublicKey to be used for signature verifying with the DSA algorithm, uses a proper getInstance method of the java.security.KeyPairGenerator class, which subsequently maybe casted to DSAKeyPairGenerator for performing an algorithm-specific initialization with proper DSA parameters. If an algorithm-specific initialization is not required, the cast to DSAKeyPairGenerator can be omitted.

Generally four steps have to be performed for creating a DSAPublicKey by using a proper KeyPairGenerator:

For performing an algorithm-specific initialization with particular DSA parameters (which may be an instance of DSAParams representing the public parameter values p, q and g), an explicit cast of the KeyPairGenerator will be necessary for obtaining a specific DSAKeyPairGenerator to be initialized with the desired DSA parameters:

 DSAKeyPairGenerator dsa_key_gen = (DSAKeyPairGenerator)key_gen;
 dsa_key_gen.initialize(dsa_params, random);
 

(where random denotes some random seed)

Guidelines on how to create some key using a KeyPairGenerator can be found in http://java.sun.com/products/JDK/1.1/docs/guide/security/CryptoSpec.html.

See Also:
PublicKeyInfo, DSAPublicKey, KeyPairGenerator, KeyPair, DSA, RawDSA, DSAPrivateKey, DSAKeyPairGenerator, DSAKeyFactory, DSAParams, Serialized Form

Fields inherited from class iaik.x509.PublicKeyInfo
public_key_algorithm
 
Fields inherited from interface java.security.interfaces.DSAPublicKey
serialVersionUID
 
Fields inherited from interface java.security.PublicKey
serialVersionUID
 
Fields inherited from interface java.security.Key
serialVersionUID
 
Constructor Summary
DSAPublicKey(ASN1Object obj)
          Creates a new DSAPublicKey from the given ASN.1 data structure representing a DSAPublicKey or PublicKeyInfo.
DSAPublicKey(java.math.BigInteger y, java.math.BigInteger p, java.math.BigInteger q, java.math.BigInteger g)
          Creates a new DSAPublicKey from the given BigInteger values.
DSAPublicKey(java.math.BigInteger y, DSAParams dsaParams)
          Creates a new DSAPublicKey from given public key value y and DSA parameters
DSAPublicKey(byte[] key)
          Creates a new DSAPublicKey from the given DER encoded ASN.1 data structure.
DSAPublicKey(DSAPublicKey pubKey)
          Creates a new DSAPublicKey from the given DSAPublicKey.
DSAPublicKey(DSAPublicKeySpec keySpec)
          Creates a new DSAPublicKey from the given DSAPublicKeySpec representing the DSA public key value y, and the public values p, q and g.
DSAPublicKey(java.io.InputStream is)
          Creates a new DSAPublicKey from an InputStream.
 
Method Summary
protected  void decode(byte[] publicKey)
          Decodes a DSAPublicKey, encoded in DER format.
protected  byte[] encode()
          DER encodes this DSAPublicKey.
 boolean equals(java.lang.Object obj)
          Compares this DSAPublicKey with the given DSAPublicKey.
 java.lang.String getAlgorithm()
          Returns the String "DSA"
 DSAParams getParams()
          Returns the DSA parameters prime p, sub-prime q and base g as DSAParams.
 java.math.BigInteger getY()
          Returns the public key value y.
 int hashCode()
          Returns a hash code for this DSAPublicKey object.
 
Methods inherited from class iaik.x509.PublicKeyInfo
createPublicKeyInfo, decode, getEncoded, getFingerprint, getFormat, getPublicKey, getPublicKey, toASN1Object, toString, writeTo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DSAPublicKey

public DSAPublicKey(java.math.BigInteger y,
                    DSAParams dsaParams)
Creates a new DSAPublicKey from given public key value y and DSA parameters

Parameters:
y - the BigInteger value representing the DSA public key value
dsaParams - the public DSA parameters p (prime), q (sub-prime) and g (base) as DSAParams
See Also:
DSAParams

DSAPublicKey

public DSAPublicKey(java.math.BigInteger y,
                    java.math.BigInteger p,
                    java.math.BigInteger q,
                    java.math.BigInteger g)
Creates a new DSAPublicKey from the given BigInteger values.

Parameters:
y - the BigInteger value representing the DSA public key
p - the public prime p (of a multiple length of 64 bits between 512 and 1024 bits)
q - the public sub-prime q (a 160-bit prime factor of p-1)
g - the public base g (=(h(p-1)/q)(mod p) > 1, with h < p-1)

DSAPublicKey

public DSAPublicKey(DSAPublicKeySpec keySpec)
Creates a new DSAPublicKey from the given DSAPublicKeySpec representing the DSA public key value y, and the public values p, q and g.

Parameters:
keySpec - the DSAPublicKeySpec representing the public key value y, the prime p, the sub-prime q, and the base g
See Also:
DSAPublicKeySpec

DSAPublicKey

public DSAPublicKey(DSAPublicKey pubKey)
Creates a new DSAPublicKey from the given DSAPublicKey.

Parameters:
pubKey - the DSAPublicKey

DSAPublicKey

public DSAPublicKey(byte[] key)
             throws InvalidKeyException
Creates a new DSAPublicKey from the given DER encoded ASN.1 data structure.

Parameters:
key - the byte array holding the DER encoded public key ASN.1 data structure

DSAPublicKey

public DSAPublicKey(ASN1Object obj)
             throws InvalidKeyException
Creates a new DSAPublicKey from the given ASN.1 data structure representing a DSAPublicKey or PublicKeyInfo.

Parameters:
obj - the public key ASN.1 data structure
Throws:
InvalidKeyException - if something is wrong with the key encoding

DSAPublicKey

public DSAPublicKey(java.io.InputStream is)
             throws InvalidKeyException,
                    java.io.IOException
Creates a new DSAPublicKey from an InputStream.

Parameters:
is - the input stream with the data to be read to initialize the public key
Throws:
InvalidKeyException - if something is wrong with the key encoding
java.io.IOException - if something is wrong with the file
Method Detail

getY

public java.math.BigInteger getY()
Returns the public key value y.

Specified by:
getY in interface DSAPublicKey
Returns:
the public key value y

getParams

public DSAParams getParams()
Returns the DSA parameters prime p, sub-prime q and base g as DSAParams.

Returns:
the DSAParams representing prime p, sub-prime q and base g

getAlgorithm

public java.lang.String getAlgorithm()
Returns the String "DSA"
Overrides:
getAlgorithm in class PublicKeyInfo
Tags copied from class: PublicKeyInfo
Returns:
the name of the algorithm

decode

protected void decode(byte[] publicKey)
               throws InvalidKeyException
Decodes a DSAPublicKey, encoded in DER format.

Overrides:
decode in class PublicKeyInfo
Parameters:
publicKey - the public key as DER encoded ASN.1 object
Throws:
InvalidKeyException - if the given key is not a DSA public key

encode

protected byte[] encode()
DER encodes this DSAPublicKey.

Overrides:
encode in class PublicKeyInfo
Returns:
this DSAPublicKey as DER encoded ASN.1 data structure

hashCode

public int hashCode()
Returns a hash code for this DSAPublicKey object.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

equals

public boolean equals(java.lang.Object obj)
Compares this DSAPublicKey with the given DSAPublicKey.

Overrides:
equals in class PublicKeyInfo
Parameters:
obj - the other DSAPublicKey
Returns:
true, if the two public key objects are equal, false otherwise