Oracle Security Developer Tools Crypto Java API Reference
10g (10.1.4.0.1)

B28171-01


oracle.security.crypto.core
Class PrivateKeyPKCS8

java.lang.Object
  extended byoracle.security.crypto.core.PrivateKeyPKCS8

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

public class PrivateKeyPKCS8
extends java.lang.Object
implements ASN1Object, PrivateKey, java.io.Externalizable

A class for PKCS #5 and PKCS #12 password-encrypted RSA/DSA private keys in PKCS #8 format.

When a PrivateKeyPKCS8 is constructed from components, the private key is encrypted when any of the methods getContents(), getEncoded(), output(java.io.OutputStream) or length() are called.

When a PrivateKeyPKCS8 is instantiated by inputting its encoding from a stream or file, the private key is decrypted immediately if the password has been set or made available to the constructor. If the password has not been provided, the private key will not be decrypted until the getKey() method is called. Note that the getKey() method is invoked by the methods getAlgID(), getAlgorithm(), getFormat() and getBitLength(). This class may not be backward compatible for Serialization: PKCS5 serialized objects created with PSE 2.2.2 and later until PSE 2.2.3 Build G may not be read.

See Also:
PKCS5, Serialized Form

Constructor Summary
PrivateKeyPKCS8()
          Creates a new instance with the default encryption mode for the PKCS5 class and the default random bits source.
PrivateKeyPKCS8(ASN1Sequence s)
           
PrivateKeyPKCS8(java.io.InputStream is)
          Read encrypted private key from a stream.
PrivateKeyPKCS8(int mode)
          Creates a new instance with the given PKCS#5 encryption mode and the default random bits source.
PrivateKeyPKCS8(int mode, RandomBitsSource rbs)
          Creates a new instance with the given PKCS#5 encryption mode and random bits source.
PrivateKeyPKCS8(PrivateKey key)
          Creates a new instance with the given private key and the default random bits source and mode SHA_3DES.
PrivateKeyPKCS8(PrivateKey key, int mode)
           
PrivateKeyPKCS8(PrivateKey key, int mode, RandomBitsSource rbs)
           
PrivateKeyPKCS8(PrivateKey key, RandomBitsSource rbs)
          Creates a new instance with the given private key and random bits source, using the default mode SHA_3DES.
PrivateKeyPKCS8(PrivateKey key, java.lang.String passwd, int mode)
          Creates a new instance with the given private key, password, and PKCS#5 encryption mode, and the default random bits source.
PrivateKeyPKCS8(PrivateKey key, java.lang.String passwd, int mode, RandomBitsSource rbs)
          Creates a new instance with the given private key, password, PKCS#5 encryption mode and random bits source.
PrivateKeyPKCS8(java.lang.String password, ASN1Sequence s)
          Read encrypted private key from an ASN1 encoding.
PrivateKeyPKCS8(java.lang.String password, java.io.File f)
          Read encrypted private key from a file.
PrivateKeyPKCS8(java.lang.String password, java.io.InputStream is)
          Read encrypted private key from a stream.
PrivateKeyPKCS8(java.lang.String passwd, PrivateKey key)
          Uses the default mode SHA_3DES and the default RandomBitsSource.
PrivateKeyPKCS8(java.lang.String passwd, PrivateKey key, RandomBitsSource rbs)
          Uses the default mode SHA_3DES.

 

Method Summary
 java.lang.Object clone()
          Creates a clone of the instance.
 void erase()
          Erases the key material, making the key un-usable.
 AlgorithmIdentifier getAlgID()
          Returns the AlgorithmIdentifier of the underlying PrivateKey, or null if the key has not been input or set, or the key cannot be decrypted.
 java.lang.String getAlgorithm()
          Returns the algorithm of the underlying PrivateKey, or null if the underlying key hasn't been input or set, or if the key cannot be decrypted.
 int getBitLength()
          Returns the bit length of the underlying PrivateKey or 0 if the underlying key hasn't been input or set or if the key cannot be decrypted.
 ASN1Object getContents()
          Returns the ASN1Object that is output to the output(OutputStream os) method.
 byte[] getEncoded()
          Returns the bytes that are output from the output(OutputStream os) method.
 java.lang.String getFormat()
          Returns the format of the underlying PrivateKey or null if the underlying key hasn't been input or set, or if the key cannot be decrypted.
 PrivateKey getKey()
          Get the private key.
 int getMode()
          Returns the mode for PKCS5/12.
 void initialize(AlgorithmIdentifier algID, ASN1Object contents)
          Initializes the underlying PrivateKey, creating a new instance if one does not already exist.
 void input(ASN1Sequence s)
           
 void input(java.io.InputStream is)
          Inputs this object from the specified input stream.
 int length()
          Length of this object's encoding.
 void output(java.io.OutputStream os)
          Outputs this object to the specified output stream.
 void readExternal(java.io.ObjectInput is)
           
 void setCount(int c)
          Set the count for PKCS5/12.
 void setKey(PrivateKey key)
          Set the private key.
 void setMode(int m)
          Set the mode for PKCS5/12.
 void setPassword(java.lang.String pw)
          Set the password for PKCS5/12.
 void setSalt(byte[] salt)
          Set the salt for PKCS5/12.
 java.lang.String toString()
          Returns a string representation of this object.
 void writeExternal(java.io.ObjectOutput os)
           

 

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

 

Constructor Detail

PrivateKeyPKCS8

public PrivateKeyPKCS8()
Creates a new instance with the default encryption mode for the PKCS5 class and the default random bits source.

PrivateKeyPKCS8

public PrivateKeyPKCS8(int mode,
                       RandomBitsSource rbs)
Creates a new instance with the given PKCS#5 encryption mode and random bits source.

PrivateKeyPKCS8

public PrivateKeyPKCS8(int mode)
Creates a new instance with the given PKCS#5 encryption mode and the default random bits source.

PrivateKeyPKCS8

public PrivateKeyPKCS8(PrivateKey key,
                       RandomBitsSource rbs)
Creates a new instance with the given private key and random bits source, using the default mode SHA_3DES.

PrivateKeyPKCS8

public PrivateKeyPKCS8(PrivateKey key)
Creates a new instance with the given private key and the default random bits source and mode SHA_3DES.

PrivateKeyPKCS8

public PrivateKeyPKCS8(PrivateKey key,
                       int mode,
                       RandomBitsSource rbs)

PrivateKeyPKCS8

public PrivateKeyPKCS8(PrivateKey key,
                       int mode)

PrivateKeyPKCS8

public PrivateKeyPKCS8(java.lang.String passwd,
                       PrivateKey key,
                       RandomBitsSource rbs)
Uses the default mode SHA_3DES.

PrivateKeyPKCS8

public PrivateKeyPKCS8(java.lang.String passwd,
                       PrivateKey key)
Uses the default mode SHA_3DES and the default RandomBitsSource.

PrivateKeyPKCS8

public PrivateKeyPKCS8(PrivateKey key,
                       java.lang.String passwd,
                       int mode,
                       RandomBitsSource rbs)
Creates a new instance with the given private key, password, PKCS#5 encryption mode and random bits source.

PrivateKeyPKCS8

public PrivateKeyPKCS8(PrivateKey key,
                       java.lang.String passwd,
                       int mode)
Creates a new instance with the given private key, password, and PKCS#5 encryption mode, and the default random bits source.

PrivateKeyPKCS8

public PrivateKeyPKCS8(java.lang.String password,
                       java.io.InputStream is)
                throws java.io.IOException
Read encrypted private key from a stream.

PrivateKeyPKCS8

public PrivateKeyPKCS8(java.io.InputStream is)
                throws java.io.IOException
Read encrypted private key from a stream.
See Also:
setPassword(java.lang.String)

PrivateKeyPKCS8

public PrivateKeyPKCS8(ASN1Sequence s)
                throws java.io.IOException

PrivateKeyPKCS8

public PrivateKeyPKCS8(java.lang.String password,
                       java.io.File f)
                throws java.io.IOException,
                       java.io.FileNotFoundException
Read encrypted private key from a file.

PrivateKeyPKCS8

public PrivateKeyPKCS8(java.lang.String password,
                       ASN1Sequence s)
                throws java.io.IOException
Read encrypted private key from an ASN1 encoding.

Method Detail

input

public void input(java.io.InputStream is)
           throws java.io.IOException
Description copied from interface: Streamable
Inputs this object from the specified input stream.
Specified by:
input in interface Streamable
Throws:
java.io.IOException

input

public void input(ASN1Sequence s)
           throws java.io.IOException
Throws:
java.io.IOException

output

public void output(java.io.OutputStream os)
            throws java.io.IOException
Description copied from interface: Streamable
Outputs this object to the specified output stream.
Specified by:
output in interface Streamable
Throws:
java.io.IOException

length

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

setPassword

public void setPassword(java.lang.String pw)
Set the password for PKCS5/12.

setMode

public void setMode(int m)
Set the mode for PKCS5/12.

getMode

public int getMode()
Returns the mode for PKCS5/12.

setCount

public void setCount(int c)
Set the count for PKCS5/12.

setSalt

public void setSalt(byte[] salt)
Set the salt for PKCS5/12.

getKey

public PrivateKey getKey()
Get the private key.
Throws:
java.lang.IllegalStateException - If an error occurs while decrypting the private key.

setKey

public void setKey(PrivateKey key)
Set the private key.

toString

public java.lang.String toString()
Returns a string representation of this object.
Returns:
A string representation of this object

getAlgID

public AlgorithmIdentifier getAlgID()
Returns the AlgorithmIdentifier of the underlying PrivateKey, or null if the key has not been input or set, or the key cannot be decrypted.
Specified by:
getAlgID in interface PrivateKey

getContents

public ASN1Object getContents()
Returns the ASN1Object that is output to the output(OutputStream os) method.
Specified by:
getContents in interface PrivateKey
Throws:
StreamableOutputException - If an error occurs generating the output (e.g., key encryption fails).

initialize

public void initialize(AlgorithmIdentifier algID,
                       ASN1Object contents)
                throws InvalidInputException,
                       AlgorithmIdentifierException
Initializes the underlying PrivateKey, creating a new instance if one does not already exist.
Specified by:
initialize in interface PrivateKey
Parameters:
algID - The algorithm identifier of the enclosed private key.
contents - The ASN.1 DER-encoded bytes of the private key.
Throws:
InvalidInputException
AlgorithmIdentifierException

clone

public java.lang.Object clone()
Creates a clone of the instance. If a RandomBitsSource was specified for this instance, the new instance will use the same RandomBitsSource.
Specified by:
clone in interface Key

erase

public void erase()
Description copied from interface: Key
Erases the key material, making the key un-usable.

Keys can be erased multiple times with no consequence.

Specified by:
erase in interface Key

getAlgorithm

public java.lang.String getAlgorithm()
Returns the algorithm of the underlying PrivateKey, or null if the underlying key hasn't been input or set, or if the key cannot be decrypted.
Specified by:
getAlgorithm in interface Key

getBitLength

public int getBitLength()
Returns the bit length of the underlying PrivateKey or 0 if the underlying key hasn't been input or set or if the key cannot be decrypted.
Specified by:
getBitLength in interface Key

getEncoded

public byte[] getEncoded()
Returns the bytes that are output from the output(OutputStream os) method.
Specified by:
getEncoded in interface Key
Throws:
StreamableOutputException - If an error occurs generating the output bytes (e.g., key encryption fails).

getFormat

public java.lang.String getFormat()
Returns the format of the underlying PrivateKey or null if the underlying key hasn't been input or set, or if the key cannot be decrypted.
Specified by:
getFormat in interface Key

writeExternal

public void writeExternal(java.io.ObjectOutput os)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput is)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

Oracle Security Developer Tools Crypto Java API Reference
10g (10.1.4.0.1)

B28171-01


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