Skip navigation links

Oracle Fusion Middleware Crypto Java API Reference for Oracle Security Developer Tools
11g Release 1 (11.1.1)

E10668-03


oracle.security.crypto.core
Class DSAPrivateKey

java.lang.Object
  extended by oracle.security.crypto.core.DSAPrivateKey

All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.security.interfaces.DSAKey, java.security.interfaces.DSAPrivateKey, java.security.Key, java.security.PrivateKey, ASN1Object, Streamable

public class DSAPrivateKey
extends java.lang.Object
implements PrivateKey, ASN1Object, java.security.interfaces.DSAPrivateKey

A DSA private key.

A DSA private key contains, in addition to the DSA parameters p, q, and g, an additional integer, x.

The OID used to identify the key algorithm may be set via setKeyAlgOID. The encoding used for keys of this class is based on the PrivateKeyInfo structure of PKCS #8, and is compatible with that used in JDK 1.2.

Note: To input a DSA private key (e.g., from a file), it is preferred to use CryptoUtils.inputPrivateKey. This method is required to input a CDSA format DSA private key.

See Also:
CryptoUtils.inputPrivateKey(java.io.File), Serialized Form

Field Summary

 

Fields inherited from interface java.security.interfaces.DSAPrivateKey
serialVersionUID

 

Constructor Summary
DSAPrivateKey()
          Creates a new uninitialized DSAPrivateKey instance.
DSAPrivateKey(ASN1Sequence s)
          Deprecated. Use DSAPrivateKey(InputStream is) instead.
DSAPrivateKey(java.math.BigInteger x, DSAParams params)
          Makes a new instance with the give value of x and DSAParams.
DSAPrivateKey(byte[] data)
          Makes a new instance by reading its encoding from the given byte array.
DSAPrivateKey(java.io.File f)
          Makes a new instance by reading its encoding from the given file.
DSAPrivateKey(java.io.InputStream is)
          Makes a new instance by reading its encoding from the given InputStream.

 

Method Summary
 java.lang.Object clone()
          Creates a deep copy of this DSAPrivateKey instance.
 void erase()
          Erases the key material making the key un-usable.
 void finalize()
          Erases this object prior to being reclaimed by the garbage collector.
 AlgorithmIdentifier getAlgID()
          Returns the algorithm identifier for this key.
 java.lang.String getAlgorithm()
          Gets the algorithm name for this key.
 boolean getAllowExport()
          Returns false if plaintext export of this key's key material is not allowed; returns true if plaintext export is allowed.
 int getBitLength()
          Returns the number of bits needed to represent the DSAPrivateKey's public component P.
 ASN1Object getContents()
          Returns the contents of this key.
 byte[] getEncoded()
          Returns ASN.1 DER bytes containing the PKCS#8 PrivateKeyInfo encoding of this private key.
 java.lang.String getFormat()
          Returns a string which indicates the format of this object's encoding.
 ASN1ObjectID getKeyAlgOID()
          Returns the key algorithm OID.
 DSAParams getParams()
          Returns the DSA algorithm parameters for this private key.
 java.math.BigInteger getX()
          Returns the private key value x.
 void initialize(AlgorithmIdentifier algID, ASN1Object contents)
          Initializes this instance from the given algorithm paramters and key contents.
 void input(java.io.InputStream is)
          Inputs a DSAPrivateKey object by reading its encoding from the given input stream.
 int length()
          Gets the length of the encoding of this object.
 void output(java.io.OutputStream os)
          Outputs encoding of this object to a given output stream.
 void readExternal(java.io.ObjectInput is)
          Reads the input stream and initializes the DSA private key.
 void setAllowExport(boolean value)
          Set to false to disallow plaintext export of this key's key material; set to true to allow plaintext export if the global value in FIPS_140_2 is also set to true.
 void setKeyAlgOID(ASN1ObjectID oid)
          Sets the key algorithm OID.
 void setParams(DSAParams params)
          Sets the DSA algorithm parameters for this public key.
 java.lang.String toString()
          Returns a description of this private key.
 void writeExternal(java.io.ObjectOutput os)
          Writes to the output stream the DER encoding of this object.

 

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Constructor Detail

DSAPrivateKey

public DSAPrivateKey()
Creates a new uninitialized DSAPrivateKey instance.

DSAPrivateKey

public DSAPrivateKey(java.math.BigInteger x,
                     DSAParams params)
Makes a new instance with the give value of x and DSAParams.
Parameters:
x - The private key value x.
params - The DSAParams for this DSAPrivateKey.

DSAPrivateKey

public DSAPrivateKey(java.io.File f)
              throws java.io.IOException
Makes a new instance by reading its encoding from the given file.
Parameters:
f - The file from which the DSAPrivateKey object will be read.
Throws:
java.io.IOException - If an input exception occured.

DSAPrivateKey

public DSAPrivateKey(byte[] data)
              throws java.io.IOException
Makes a new instance by reading its encoding from the given byte array.
Parameters:
data - The byte array from which the DSAPrivateKey object will be read.
Throws:
java.io.IOException - If an input exception occured.

DSAPrivateKey

public DSAPrivateKey(java.io.InputStream is)
              throws java.io.IOException
Makes a new instance by reading its encoding from the given InputStream.
Parameters:
is - The InputStream from which the DSAPrivateKey object will be read.
Throws:
java.io.IOException - If an input exception occured.

DSAPrivateKey

public DSAPrivateKey(ASN1Sequence s)
              throws java.io.IOException
Deprecated. Use DSAPrivateKey(InputStream is) instead.
Throws:
java.io.IOException

Method Detail

getFormat

public java.lang.String getFormat()
Returns a string which indicates the format of this object's encoding.
Specified by:
getFormat in interface java.security.Key
Returns:
"PKCS#8"

getAlgorithm

public java.lang.String getAlgorithm()
Gets the algorithm name for this key.
Specified by:
getAlgorithm in interface java.security.Key
Returns:
"DSA"

erase

public void erase()
Erases the key material making the key un-usable.

Keys can be erased multiple times with no consequence.


finalize

public void finalize()
Erases this object prior to being reclaimed by the garbage collector.

Note: There is no guarantee of when, if ever, finalize will be invoked by the Java runtime.

Overrides:
finalize in class java.lang.Object

clone

public java.lang.Object clone()
Creates a deep copy of this DSAPrivateKey instance.
Overrides:
clone in class java.lang.Object
Returns:
A deep clone of the Key instance.

getBitLength

public int getBitLength()
Returns the number of bits needed to represent the DSAPrivateKey's public component P.

0 will be returned if the key has not been initialized.


getEncoded

public byte[] getEncoded()
Returns ASN.1 DER bytes containing the PKCS#8 PrivateKeyInfo encoding of this private key.
Specified by:
getEncoded in interface java.security.Key

getAllowExport

public boolean getAllowExport()
Returns false if plaintext export of this key's key material is not allowed; returns true if plaintext export is allowed.

If either this value or the global value is false, the output(java.io.OutputStream), getContents() and getEncoded() methods will throw a KeyExportException.

Returns:
false if plaintext key material export is not allowed, true if allowed.
Since:
3.0
See Also:
FIPS_140_2.getAllowKeyExport(), Cipher.wrapKey(PrivateKey key)

setAllowExport

public void setAllowExport(boolean value)
Set to false to disallow plaintext export of this key's key material; set to true to allow plaintext export if the global value in FIPS_140_2 is also set to true.

If either this value or the global value is false, the output(java.io.OutputStream), getContents() and getEncoded() methods will throw a KeyExportException.

Parameters:
value - false to disallow plaintext key material export, true to allow.
Since:
3.0
See Also:
FIPS_140_2.setAllowKeyExport(boolean), Cipher.wrapKey(PrivateKey key)

initialize

public void initialize(AlgorithmIdentifier algID,
                       ASN1Object contents)
                throws AlgorithmIdentifierException,
                       InvalidInputException
Description copied from interface: PrivateKey
Initializes this instance from the given algorithm paramters and key contents.
Throws:
AlgorithmIdentifierException
InvalidInputException

getAlgID

public AlgorithmIdentifier getAlgID()
Description copied from interface: PrivateKey
Returns the algorithm identifier for this key.

getContents

public ASN1Object getContents()
Description copied from interface: PrivateKey
Returns the contents of this key.

getX

public java.math.BigInteger getX()
Returns the private key value x.
Specified by:
getX in interface java.security.interfaces.DSAPrivateKey
Returns:
The private key value x.

setParams

public void setParams(DSAParams params)
Sets the DSA algorithm parameters for this public key.

getParams

public DSAParams getParams()
Returns the DSA algorithm parameters for this private key.
Specified by:
getParams in interface java.security.interfaces.DSAKey
Returns:
The algorithm parameters.

toString

public java.lang.String toString()
Returns a description of this private key.
Overrides:
toString in class java.lang.Object

getKeyAlgOID

public ASN1ObjectID getKeyAlgOID()
Returns the key algorithm OID. If no key algorithm OID has been set, then the default, DSA.dsaKeyOID, is returned.
Returns:
The key algorithm OID.
See Also:
DSA.dsaKeyOID

setKeyAlgOID

public void setKeyAlgOID(ASN1ObjectID oid)
Sets the key algorithm OID.
Parameters:
oid - The key algorithm OID.

input

public void input(java.io.InputStream is)
           throws java.io.IOException
Inputs a DSAPrivateKey object by reading its encoding from the given input stream.
Specified by:
input in interface Streamable
Parameters:
is - The input stream from which this object will be read.
Throws:
java.io.IOException - If an input exception occured.

output

public void output(java.io.OutputStream os)
            throws java.io.IOException
Outputs encoding of this object to a given output stream.
Specified by:
output in interface Streamable
Parameters:
os - The output stream to which the encoding of this object will be written.
Throws:
java.io.IOException - If an output exception occured.

length

public int length()
Gets the length of the encoding of this object.
Specified by:
length in interface Streamable
Returns:
The length of the encoding of this object.

writeExternal

public void writeExternal(java.io.ObjectOutput os)
                   throws java.io.IOException
Writes to the output stream the DER encoding of this object.
Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
os - The output stream to write the encoding to.
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput is)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Reads the input stream and initializes the DSA private key.
Specified by:
readExternal in interface java.io.Externalizable
Parameters:
is - The stream to read from.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

Skip navigation links

Oracle Fusion Middleware Crypto Java API Reference for Oracle Security Developer Tools
11g Release 1 (11.1.1)

E10668-03


Copyright © 2005, 2011 , Oracle. All rights reserved.