public class DSAPublicKey extends PublicKeyInfo implements java.security.interfaces.DSAPublicKey
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, which length is a multiple of 64 bits lying
between 512 and 1024 bits
q) of p-1
(h(p-1)/q)(mod p) > 1
g = (h(p-1)/q)(mod p)
x less than q
y calculated from y = (gx)(mod p)
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:
KeyPairGenerator has to be instantiated thereby specifying
the application's intention to create keys for use within the DSA algorithm:
KeyPairGenerator key_gen = KeyPairGenerator.getInstance("DSA");
initialize method. For initializing the generator to create keys with
a modulus length of, e.g., 1024 bits, this can be explicitly specified (1024 bits
also is the default value for the modulus length when not explicitly initializing
the generator):
key_gen.initialize(1024);
generateKeyPair():
KeyPair key_pair = key_gen.generateKeyPair();
DSAPublicKey dsa_pub_key = (DSAPublicKey)key_pair.getPublic();
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.
PublicKeyInfo,
DSAPublicKey,
KeyPairGenerator,
KeyPair,
DSA,
RawDSA,
DSAPrivateKey,
DSAKeyPairGenerator,
DSAKeyFactory,
DSAParams,
Serialized Formpublic_key_algorithm| Constructor and Description |
|---|
DSAPublicKey(ASN1Object obj)
Creates a new DSAPublicKey from the given ASN.1 object.
|
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,
java.security.interfaces.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(java.security.interfaces.DSAPublicKey pubKey)
Creates a new DSAPublicKey from the given DSAPublicKey.
|
DSAPublicKey(java.security.spec.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.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
decode(byte[] publicKey)
Decodes a DSAPublicKey, encoded in DER format.
|
byte[] |
encode()
Returns the raw DSA public key (not wrapped by a X.509 PublicKeyInfo)
as DER encoded ASN.1 object.
|
boolean |
equals(java.lang.Object obj)
Compares this DSAPublicKey with the given DSAPublicKey.
|
java.lang.String |
getAlgorithm()
Returns the String "DSA"
|
java.security.interfaces.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.
|
java.lang.String |
toString()
Returns a string that represents the contents of this private key.
|
clone, createPublicKeyInfo, decode, getAlgorithmID, getEncoded, getFingerprint, getFormat, getPublicKey, getPublicKey, getPublicKey, getPublicKey, toASN1Object, writeTopublic DSAPublicKey(java.math.BigInteger y,
java.security.interfaces.DSAParams dsaParams)
y - the BigInteger value representing the DSA public key valuedsaParams - the public DSA parameters p (prime), q (sub-prime) and g
(base) as DSAParamsDSAParamspublic DSAPublicKey(java.math.BigInteger y,
java.math.BigInteger p,
java.math.BigInteger q,
java.math.BigInteger g)
y - the BigInteger value representing the DSA public keyp - 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)public DSAPublicKey(java.security.spec.DSAPublicKeySpec keySpec)
keySpec - the DSAPublicKeySpec representing the public key value y,
the prime p, the sub-prime q, and the base gDSAPublicKeySpecpublic DSAPublicKey(java.security.interfaces.DSAPublicKey pubKey)
pubKey - the DSAPublicKeypublic DSAPublicKey(byte[] key)
throws java.security.InvalidKeyException
This constructor may be used for parsing an already existing
DSA public key, wrapped into a X.509 PublicKeyInfo that is supplied as DER encoded byte array.
key - the byte array holding the DER encoded public key infojava.security.InvalidKeyException - if something is wrong with the key encodingpublic DSAPublicKey(ASN1Object obj) throws java.security.InvalidKeyException
PublicKeyInfo holding the DSA public key.obj - the public key ASN.1 data structurejava.security.InvalidKeyException - if something is wrong with the key encodingpublic DSAPublicKey(java.io.InputStream is)
throws java.security.InvalidKeyException,
java.io.IOException
This constructor may be used for parsing an already existing
DH public key, wrapped into a X.509 PublicKeyInfo that is supplied as DER encoded byte array.
is - the input stream with the data to be read to initialize the public keyjava.security.InvalidKeyException - if something is wrong with the key encodingjava.io.IOException - if something is wrong with the filepublic java.math.BigInteger getY()
getY in interface java.security.interfaces.DSAPublicKeypublic java.security.interfaces.DSAParams getParams()
getParams in interface java.security.interfaces.DSAKeypublic java.lang.String getAlgorithm()
getAlgorithm in interface java.security.KeygetAlgorithm in class PublicKeyInfoprotected void decode(byte[] publicKey)
throws java.security.InvalidKeyException
This method is protected and typically will not be used by an application. Rather
it is used by the parent X.509 PublicKeyInfo class for decoding the inherent DSA public key.
decode in class PublicKeyInfopublicKey - the public key as DER encoded ASN.1 objectjava.security.InvalidKeyException - if the given key is not a DSA public keypublic byte[] encode()
This method typically may not be used by an application. Rather
it is used by the parent X.509 PublicKeyInfo class for encoding the inherent DSA public key.
encode in class PublicKeyInfopublic int hashCode()
hashCode in class PublicKeyInfopublic boolean equals(java.lang.Object obj)
equals in class PublicKeyInfoobj - the other DSAPublicKeytrue, if the two public key objects are equal, false otherwisepublic java.lang.String toString()
toString in class PublicKeyInfo