public class DSAPrivateKey extends PrivateKeyInfo implements java.security.interfaces.DSAPrivateKey
This class extends iaik.pkcs.pkcs8.PrivateKeyInfo
for supporting
the PKCS#8 Private Key Information Standard for the DSA private keys. This
class implements the java.security.interfaces.DSAPrivateKey
interface for providing the functionality of a private key used for signing
some data 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 DSAPrivateKey to be used for data signing
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 DSAPrivateKey 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();
DSAPrivateKey dsa_priv_key = (DSAPrivateKey) key_pair.getPrivate();
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.
PrivateKeyInfo
,
DSAPrivateKey
,
KeyPairGenerator
,
KeyPair
,
DSA
,
RawDSA
,
DSAPublicKey
,
DSAKeyPairGenerator
,
DSAKeyFactory
,
DSAParams
,
Serialized Formprivate_key_algorithm
Constructor and Description |
---|
DSAPrivateKey(ASN1Object obj)
Creates a new DSAPrivateKey from the given ASN.1 object.
|
DSAPrivateKey(java.math.BigInteger x,
java.math.BigInteger p,
java.math.BigInteger q,
java.math.BigInteger g)
Creates a new DSAPrivateKey from the given BigInteger values.
|
DSAPrivateKey(java.math.BigInteger x,
java.security.interfaces.DSAParams dsaParams)
Creates a new DSAPrivateKey from given private key value x and DSA
parameters
|
DSAPrivateKey(byte[] key)
Creates a new DSAPrivateKey from the given DER encoded byte array.
|
DSAPrivateKey(java.security.interfaces.DSAPrivateKey privKey)
Creates a new DSAPrivateKey from the given DSAPrivateKey.
|
DSAPrivateKey(java.security.spec.DSAPrivateKeySpec keySpec)
Creates a new DSAPrivateKey from the given DSAPrivateKeySpec representing
the DSA private key value x, and the public values p, q and g.
|
DSAPrivateKey(java.io.InputStream is)
Creates a new DSAPrivateKey from an InputStream.
|
Modifier and Type | Method and Description |
---|---|
protected void |
decode(byte[] privateKey)
Decodes a DER encoded DSA private key.
|
byte[] |
encode()
Returns the raw DSA private key (not wrapped by a PKCS#8 PrivateKeyInfo) as
DER encoded byte array.
|
boolean |
equals(java.lang.Object obj)
Compares this DSAPrivateKey with the given DSAPrivateKey.
|
java.lang.String |
getAlgorithm()
Returns the name of the appertaining algorithm.
|
java.security.interfaces.DSAParams |
getParams()
Returns the DSA parameters prime p, sub-prime q and base g as DSAParams.
|
java.math.BigInteger |
getX()
Returns the private key value x.
|
int |
hashCode()
Returns a hash code for this DSAPrivateKey object.
|
java.lang.String |
toString()
Returns a string that represents the contents of this private key.
|
clone, createPrivateKeyInfo, decode, getAlgorithmID, getAttributes, getEncoded, getFormat, getPrivateKey, getPrivateKey, getPrivateKey, getPrivateKey, getPrivateKey, getPrivateKey, getPubKey, setAttributes, setPubKey, toASN1Object, writeTo
public DSAPrivateKey(java.math.BigInteger x, java.security.interfaces.DSAParams dsaParams)
x
- the BigInteger value representing the DSA private key valuedsaParams
- the public DSA parameters p (prime), q (sub-prime) and g (base) as
DSAParamsDSAParams
public DSAPrivateKey(java.math.BigInteger x, java.math.BigInteger p, java.math.BigInteger q, java.math.BigInteger g)
x
- the BigInteger value representing the DSA private 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 DSAPrivateKey(java.security.spec.DSAPrivateKeySpec keySpec)
keySpec
- the DSAPrivateKeySpec representing the private key value x, the
prime p, the sub-prime q, and the base gDSAPrivateKeySpec
public DSAPrivateKey(java.security.interfaces.DSAPrivateKey privKey)
privKey
- the DSAPrivateKeypublic DSAPrivateKey(byte[] key) throws java.security.InvalidKeyException
key
- the byte array holding the DER encoded private key ASN.1 data
structurejava.security.InvalidKeyException
- if something is wrong with the encoding of the keypublic DSAPrivateKey(ASN1Object obj) throws java.security.InvalidKeyException
PrivateKeyInfo
holding the DSA
private key.obj
- the private key ASN.1 data structurejava.security.InvalidKeyException
- if something is wrong with the key encodingpublic DSAPrivateKey(java.io.InputStream is) throws java.security.InvalidKeyException, java.io.IOException
This constructor may be used for parsing an already existing DSA private
key, wrapped into a PKCS#8 PrivateKeyInfo
that is supplied as DER encoded byte array.
is
- the input stream with the data to be read to initialize the
private keyjava.security.InvalidKeyException
- if something is wrong with the key encodingjava.io.IOException
- if an I/O error occurspublic java.math.BigInteger getX()
getX
in interface java.security.interfaces.DSAPrivateKey
public java.security.interfaces.DSAParams getParams()
getParams
in interface java.security.interfaces.DSAKey
public byte[] encode()
This method typically may not be used by an application. Rather it is used
by the parent PKCS#8 PrivateKeyInfo
class for encoding the inherent DSA private key.
encode
in class PrivateKeyInfo
protected void decode(byte[] privateKey) throws java.security.InvalidKeyException
This method is protected and typically will not be used by an application.
Rather it is used by the parent PKCS#8
PrivateKeyInfo
class for decoding
the inherent DSA private key.
decode
in class PrivateKeyInfo
privateKey
- the DSA private key as DER encoded byte arrayjava.security.InvalidKeyException
- if the given key is not a DSA private keypublic java.lang.String getAlgorithm()
getAlgorithm
in interface java.security.Key
getAlgorithm
in class PrivateKeyInfo
public int hashCode()
hashCode
in class PrivateKeyInfo
public boolean equals(java.lang.Object obj)
equals
in class PrivateKeyInfo
obj
- the other DSAPrivateKeytrue
, if the two private key objects are equal,
false
otherwisepublic java.lang.String toString()
toString
in class PrivateKeyInfo