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

B28171-01


oracle.security.crypto.core
Class PKCS5

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

All Implemented Interfaces:
ASN1Object, java.io.Serializable, Streamable

public class PKCS5
extends java.lang.Object
implements ASN1Object, java.io.Serializable

This class implements PKCS #5 and PKCS #12 password-based encryption. The methods encrypt() and decrypt() perform encryption or decryption based on the mode and password.

Please note that PKCS5 is the encryption algorithm used to encrypt and decrypt private keys, encapsulated by the PrivateKeyPKCS8 class.

See Also:
PrivateKeyPKCS8, Serialized Form

Field Summary
static int DEFAULT_ITER_COUNT
          Default password-based key derivation iteration count is 1024.
static int DEFAULT_SALT_LEN
          Default password-based key derivation salt length is 8 bytes.
static int MD2_DES
          Encryption mode identifier for MD2 with DES.
static int MD5_DES
          Encryption mode identifier for MD5 with DES.
static int NONE
          Indicates that no encryption mode is set.
static int SHA_128RC2
          Encryption mode identifier for SHA-1 with 128-bit RC2.
static int SHA_128RC4
          Encryption mode identifier for SHA-1 with 128-bit RC4.
static int SHA_2DES
          Encryption mode identifier for SHA-1 with two-key DES.
static int SHA_3DES
          Encryption mode identifier for SHA-1 with triple-DES.
static int SHA_40RC2
          Encryption mode identifier for SHA-1 with 40-bit RC2.
static int SHA_40RC4
          Encryption mode identifier for SHA-1 with 40-bit RC4.

 

Constructor Summary
PKCS5()
          Creates a new PKCS5 instance.
PKCS5(byte[] p, byte[] s, int c)
          Creates a new PKCS5 instance with the given password, salt and count, and MD5_DES encryption mode.
PKCS5(byte[] p, byte[] s, int c, int m)
          Creates a new PKCS5 instance with the given password, salt, count and mode.
PKCS5(int m)
          Creates a new PKCS5 instance with the given mode ID, and default iteration count and source of randomness.
PKCS5(int m, int c, RandomBitsSource rbs)
          Creates a new PKCS5 instance.
PKCS5(int m, RandomBitsSource rbs)
          Creates a new PKCS5 instance with the given mode and source of randomness, and the default iteration count.
PKCS5(RandomBitsSource rbs)
          Creates a new PKCS5 instance with the given source of randomness, and the default mode and iteration count.
PKCS5(java.lang.String p, byte[] s, int m)
          Creates a new PKCS5 instance with the given password, salt and mode, and the default iteration count.
PKCS5(java.lang.String p, byte[] s, int c, int m)
          Creates a new PKCS5 instance with the given password, salt, count and mode.
PKCS5(java.lang.String p, int m, int c, RandomBitsSource rbs)
          Creates a new PKCS5 instance with the given password, salt, count, mode and source of randomness.
PKCS5(java.lang.String p, int m, RandomBitsSource rbs)
          Creates a new PKCS5 instance with the given password, mode and source of randomness, and the default iteration count.
PKCS5(java.lang.String p, RandomBitsSource rbs)
          Creates a new PKCS5 instance with the given password and source of randomness, and the default mode and iteration count.

 

Method Summary
 java.lang.String algName()
           
 byte[] decrypt(byte[] data)
          Decrypt an array of bytes, and return the decrypted array of bytes.
 byte[] encrypt(byte[] data)
          Encrypt an array of bytes, and return the encrypted array of bytes.
 int encryptedLength(int dataLen)
           
 int getCount()
           
 int getMode()
           
 ASN1ObjectID getModeID()
           
 java.lang.String getPassword()
           
 byte[] getSalt()
           
 void input(java.io.InputStream is)
          Reconstructs this object by reading its DER encoding from the specified input stream.
 void inputAlgID(ASN1Sequence s)
           
 void inputAlgID(java.io.InputStream is)
           
 int length()
          Returns the length of this object's DER encoding.
static java.lang.String modeString(int mode)
           
 void output(java.io.OutputStream os)
          Outputs the DER encoding of this object to the specified output stream.
 void outputAlgID(java.io.OutputStream os)
           
 ASN1Sequence outputAlgIDASN1()
           
 byte[] pad(byte[] bytes, int blockSize)
          Deprecated.  
static byte[] pkcs12PseudoRandomBytes(byte ID, int n, AlgorithmIdentifier hashType, java.lang.String passwd, byte[] salt, int count)
           
 void setCount(int c)
           
 void setMode(ASN1ObjectID oid)
           
 void setMode(int m)
           
 void setPassword(byte[] p)
           
 void setPassword(java.lang.String p)
           
 void setSalt(byte[] s)
           
 java.lang.String toString()
          Returns a string representation of thie object.
 byte[] unpad(byte[] bytes)
          Deprecated.  

 

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

 

Field Detail

NONE

public static final int NONE
Indicates that no encryption mode is set.
See Also:
Constant Field Values

MD2_DES

public static final int MD2_DES
Encryption mode identifier for MD2 with DES.
See Also:
Constant Field Values

MD5_DES

public static final int MD5_DES
Encryption mode identifier for MD5 with DES.
See Also:
Constant Field Values

SHA_128RC4

public static final int SHA_128RC4
Encryption mode identifier for SHA-1 with 128-bit RC4.
See Also:
Constant Field Values

SHA_40RC4

public static final int SHA_40RC4
Encryption mode identifier for SHA-1 with 40-bit RC4.
See Also:
Constant Field Values

SHA_3DES

public static final int SHA_3DES
Encryption mode identifier for SHA-1 with triple-DES.
See Also:
Constant Field Values

SHA_2DES

public static final int SHA_2DES
Encryption mode identifier for SHA-1 with two-key DES.
See Also:
Constant Field Values

SHA_128RC2

public static final int SHA_128RC2
Encryption mode identifier for SHA-1 with 128-bit RC2.
See Also:
Constant Field Values

SHA_40RC2

public static final int SHA_40RC2
Encryption mode identifier for SHA-1 with 40-bit RC2.
See Also:
Constant Field Values

DEFAULT_SALT_LEN

public static final int DEFAULT_SALT_LEN
Default password-based key derivation salt length is 8 bytes.
See Also:
Constant Field Values

DEFAULT_ITER_COUNT

public static final int DEFAULT_ITER_COUNT
Default password-based key derivation iteration count is 1024.
See Also:
Constant Field Values

Constructor Detail

PKCS5

public PKCS5()
Creates a new PKCS5 instance. The default parameters are:

PKCS5

public PKCS5(int m)
Creates a new PKCS5 instance with the given mode ID, and default iteration count and source of randomness.
Parameters:
m - The encryption mode ID.
See Also:
PKCS5()

PKCS5

public PKCS5(int m,
             int c,
             RandomBitsSource rbs)
Creates a new PKCS5 instance.
Parameters:
m - The encryption mode ID.
c - The iteration count.
rbs - The source of randomness.

PKCS5

public PKCS5(int m,
             RandomBitsSource rbs)
Creates a new PKCS5 instance with the given mode and source of randomness, and the default iteration count.
Parameters:
m - The encryption mode ID.
rbs - The source of randomness.
See Also:
PKCS5()

PKCS5

public PKCS5(RandomBitsSource rbs)
Creates a new PKCS5 instance with the given source of randomness, and the default mode and iteration count.
Parameters:
rbs - The source of randomness.
See Also:
PKCS5()

PKCS5

public PKCS5(java.lang.String p,
             byte[] s,
             int c,
             int m)
Creates a new PKCS5 instance with the given password, salt, count and mode.
Parameters:
p - The password.
s - The salt.
c - The iteration count.
m - The encryption mode.

PKCS5

public PKCS5(java.lang.String p,
             byte[] s,
             int m)
Creates a new PKCS5 instance with the given password, salt and mode, and the default iteration count.
Parameters:
p - The password.
s - The salt.
m - The encryption mode.
See Also:
PKCS5()

PKCS5

public PKCS5(java.lang.String p,
             int m,
             int c,
             RandomBitsSource rbs)
Creates a new PKCS5 instance with the given password, salt, count, mode and source of randomness.
Parameters:
p - The password.
m - The encryption mode.
c - The iteration count.
rbs - The source of randomness.

PKCS5

public PKCS5(java.lang.String p,
             int m,
             RandomBitsSource rbs)
Creates a new PKCS5 instance with the given password, mode and source of randomness, and the default iteration count.
Parameters:
p - The password.
m - The encryption mode.
rbs - The source of randomness.
See Also:
PKCS5()

PKCS5

public PKCS5(java.lang.String p,
             RandomBitsSource rbs)
Creates a new PKCS5 instance with the given password and source of randomness, and the default mode and iteration count.
Parameters:
p - The password.
rbs - The source of randomness.
See Also:
PKCS5()

PKCS5

public PKCS5(byte[] p,
             byte[] s,
             int c,
             int m)
Creates a new PKCS5 instance with the given password, salt, count and mode.
Parameters:
p - The password.
s - The salt.
c - The iteration count.
m - The encryption mode.
Since:
SSLava 1.1.1

PKCS5

public PKCS5(byte[] p,
             byte[] s,
             int c)
Creates a new PKCS5 instance with the given password, salt and count, and MD5_DES encryption mode.
Parameters:
p - The password.
s - The salt.
c - The iteration count.
Since:
SSLava 1.1.1

Method Detail

pad

public byte[] pad(byte[] bytes,
                  int blockSize)
           throws CipherException
Deprecated.  
Returns bytes padded to a multiple of blockSize.
Throws:
CipherException

unpad

public byte[] unpad(byte[] bytes)
             throws CipherException
Deprecated.  
Returns bytes unpadded.
Throws:
CipherException

encrypt

public byte[] encrypt(byte[] data)
               throws CipherException
Encrypt an array of bytes, and return the encrypted array of bytes.
Throws:
CipherException

pkcs12PseudoRandomBytes

public static byte[] pkcs12PseudoRandomBytes(byte ID,
                                             int n,
                                             AlgorithmIdentifier hashType,
                                             java.lang.String passwd,
                                             byte[] salt,
                                             int count)
                                      throws CipherException
Throws:
CipherException

decrypt

public byte[] decrypt(byte[] data)
               throws CipherException
Decrypt an array of bytes, and return the decrypted array of bytes.
Throws:
CipherException

encryptedLength

public int encryptedLength(int dataLen)

setMode

public void setMode(int m)

getMode

public int getMode()

setPassword

public void setPassword(java.lang.String p)

setPassword

public void setPassword(byte[] p)

getPassword

public java.lang.String getPassword()

setSalt

public void setSalt(byte[] s)

getSalt

public byte[] getSalt()

setCount

public void setCount(int c)

getCount

public int getCount()

setMode

public void setMode(ASN1ObjectID oid)
             throws java.io.IOException
Throws:
java.io.IOException

getModeID

public ASN1ObjectID getModeID()

outputAlgID

public void outputAlgID(java.io.OutputStream os)
                 throws java.io.IOException
Throws:
java.io.IOException

outputAlgIDASN1

public ASN1Sequence outputAlgIDASN1()

output

public void output(java.io.OutputStream os)
            throws java.io.IOException
Outputs the DER encoding of this object to the specified output stream.
Specified by:
output in interface Streamable
Parameters:
os - the output stream to which the object will be written
Throws:
java.io.IOException

inputAlgID

public void inputAlgID(java.io.InputStream is)
                throws java.io.IOException
Throws:
java.io.IOException

inputAlgID

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

input

public void input(java.io.InputStream is)
           throws java.io.IOException
Reconstructs this object by reading its DER encoding from the specified input stream.
Specified by:
input in interface Streamable
Parameters:
is - the input stream from which this object will be read
Throws:
java.io.IOException

length

public int length()
Returns the length of this object's DER encoding.
Specified by:
length in interface Streamable
Returns:
the length of this object's DER encoding

algName

public java.lang.String algName()

modeString

public static java.lang.String modeString(int mode)

toString

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

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

B28171-01


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