Skip navigation links

Oracle Security Developer Tools Crypto Java API Reference
11g (11.1.1)

E10668-02


oracle.security.crypto.core
Class RSAPrivateKey

java.lang.Object
  extended by oracle.security.crypto.core.RSAKey
      extended by oracle.security.crypto.core.RSAPrivateKey

All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, ASN1Object, Key, PrivateKey, Streamable
Direct Known Subclasses:
RSAPrivateKeyPKCS8

public class RSAPrivateKey
extends RSAKey
implements PrivateKey

An RSA private key.

RSA private keys are output in PKCS #8 PrivateKeyInfo format, and this is also the preferred format for input. However, for backwards compatibility reasons, the PKCS #1 RSAPrivateKey format is recognized for input as well.

See Also:
Serialized Form

Constructor Summary
RSAPrivateKey()
          Creates a new, uninitialized RSA private key.
RSAPrivateKey(java.math.BigInteger mod, java.math.BigInteger exp)
          Construct a new RSAPrivateKey object with the given parameters.
RSAPrivateKey(java.math.BigInteger mod, java.math.BigInteger exp, java.math.BigInteger e, java.math.BigInteger p, java.math.BigInteger q, java.math.BigInteger e1, java.math.BigInteger e2, java.math.BigInteger c)
          Construct a new RSAPrivateKey object with the given parameters.
RSAPrivateKey(byte[] encoded)
          Makes a new RSA private key from a specified encoding.
RSAPrivateKey(java.io.File f)
          Construct a new RSAPrivateKey object from a file.
RSAPrivateKey(java.io.InputStream is)
          Initializes this RSA private key by reading its encoding from the given stream.

 

Method Summary
 java.lang.Object clone()
          Creates a deep copy of this RSAPrivateKey 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.
 boolean getAllowExport()
          Returns false if plaintext export of this key's key material is not allowed; returns true if plaintext export is allowed.
 ASN1Object getContents()
          Returns this RSAPrivateKey's contents in PKCS #1 privateKey format (as opposed to PKCS #8 privateKeyInfo format).
 java.math.BigInteger getCrtCoefficient()
          Returns the CRT coefficient.
 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.
 java.math.BigInteger getPrimeExponentP()
          Returns the prime exponent p.
 java.math.BigInteger getPrimeExponentQ()
          Returns the prime exponent q.
 java.math.BigInteger getPrimeP()
          Returns the prime p.
 java.math.BigInteger getPrimeQ()
          Returns the prime q.
 java.math.BigInteger getPublicExponent()
          Returns the public exponent.
 RSAPublicKey getPublicKey()
          Get the public key from this private key.
 void initialize(AlgorithmIdentifier algID, ASN1Object contents)
          Initializes this instance from the given algorithm paramters and key contents.
 void input(java.io.InputStream is)
          Reads an RSA private key from the specified input stream.
 boolean isPublic()
          Indicates whether this is a public key.
 int length()
          Length of this object's encoding.
 void output(java.io.OutputStream os)
          Writes the DER encoding of this key in PKCS #8 privateKeyInfo format (as opposed to PKCS #1 privateKey format) to the given output stream.
 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.
 java.lang.String toString()
          Returns a description of this RSAPrivateKey.

 

Methods inherited from class oracle.security.crypto.core.RSAKey
assertAllowExport, getAlgorithm, getBitLength, getExponent, getModulus, modulusLength, readExternal, setBytes, setModulusExponent, writeExternal

 

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

 

Methods inherited from interface oracle.security.crypto.core.Key
getAlgorithm, getBitLength

 

Methods inherited from interface java.io.Externalizable
readExternal, writeExternal

 

Constructor Detail

RSAPrivateKey

public RSAPrivateKey()
Creates a new, uninitialized RSA private key.

RSAPrivateKey

public RSAPrivateKey(java.math.BigInteger mod,
                     java.math.BigInteger exp)
Construct a new RSAPrivateKey object with the given parameters.

Note: A RSAPrivateKey constructed using only the modulus and private exponent cannot be used to derive the corresponding public key, nor can it be output to a DER-encoded ASN.1 representation.

Parameters:
mod - The modulus.
exp - The private exponent.

RSAPrivateKey

public RSAPrivateKey(java.math.BigInteger mod,
                     java.math.BigInteger exp,
                     java.math.BigInteger e,
                     java.math.BigInteger p,
                     java.math.BigInteger q,
                     java.math.BigInteger e1,
                     java.math.BigInteger e2,
                     java.math.BigInteger c)
Construct a new RSAPrivateKey object with the given parameters.
Parameters:
mod - The modulus.
exp - The private exponent.
e - The public exponent.
p - A big prime p.
q - A big prime q.
e1 - Prime exponent p.
e2 - Prime exponent q.
c - The CRT coefficient.

RSAPrivateKey

public RSAPrivateKey(java.io.File f)
              throws java.io.FileNotFoundException,
                     java.io.IOException
Construct a new RSAPrivateKey object from a file.
Parameters:
f - The file that stores the RSAPrivateKey.
Throws:
java.io.FileNotFoundException - If the file does not exist.
java.io.IOException - If an input exception occured.

RSAPrivateKey

public RSAPrivateKey(byte[] encoded)
              throws java.io.IOException
Makes a new RSA private key from a specified encoding.
Parameters:
encoded - A BER encoding of an RSA private key.
Throws:
java.io.IOException

RSAPrivateKey

public RSAPrivateKey(java.io.InputStream is)
              throws java.io.IOException
Initializes this RSA private key by reading its encoding from the given stream.
Throws:
java.io.IOException

Method Detail

getEncoded

public byte[] getEncoded()
Returns ASN.1 DER bytes containing the PKCS#8 PrivateKeyInfo encoding of this private key.
Specified by:
getEncoded in interface 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.

Specified by:
getAllowExport in interface Key
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)

erase

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

Keys can be erased multiple times with no consequence.

Specified by:
erase in interface Key
Overrides:
erase in class RSAKey

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

getFormat

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

clone

public java.lang.Object clone()
Creates a deep copy of this RSAPrivateKey instance.
Specified by:
clone in interface Key
Specified by:
clone in class RSAKey
Returns:
A deep clone of the Key instance.

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.
Specified by:
initialize in interface PrivateKey
Throws:
AlgorithmIdentifierException
InvalidInputException

getContents

public ASN1Object getContents()
Returns this RSAPrivateKey's contents in PKCS #1 privateKey format (as opposed to PKCS #8 privateKeyInfo format).

To output the key in this format in DER encoding, use code like the following:

                RSAPrivateKey key = ... ;
                OutputStream os = ... ;
                key.getContents().output(os);
                
Specified by:
getContents in interface PrivateKey
See Also:
for PKCS #8 privateKeyInfo format.

getAlgID

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

isPublic

public boolean isPublic()
Indicates whether this is a public key.
Specified by:
isPublic in class RSAKey
Returns:
Always returns false.

getPublicKey

public RSAPublicKey getPublicKey()
Get the public key from this private key.

getPublicExponent

public java.math.BigInteger getPublicExponent()
Returns the public exponent.

getPrimeP

public java.math.BigInteger getPrimeP()
Returns the prime p.

getPrimeQ

public java.math.BigInteger getPrimeQ()
Returns the prime q.

getPrimeExponentP

public java.math.BigInteger getPrimeExponentP()
Returns the prime exponent p.

getPrimeExponentQ

public java.math.BigInteger getPrimeExponentQ()
Returns the prime exponent q.

getCrtCoefficient

public java.math.BigInteger getCrtCoefficient()
Returns the CRT coefficient.

input

public void input(java.io.InputStream is)
           throws java.io.IOException
Reads an RSA private key from the specified input stream.
Specified by:
input in interface Streamable
Throws:
java.io.IOException

output

public void output(java.io.OutputStream os)
            throws java.io.IOException
Writes the DER encoding of this key in PKCS #8 privateKeyInfo format (as opposed to PKCS #1 privateKey format) to the given output stream.
Specified by:
output in interface Streamable
Throws:
java.io.IOException
See Also:
for PKCS #1 privateKey format.

length

public int length()
Description copied from interface: Streamable
Length of this object's encoding.
Specified by:
length in interface Streamable

toString

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

Skip navigation links

Oracle Security Developer Tools Crypto Java API Reference
11g (11.1.1)

E10668-02


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