Class sun.security.jsafe.RSACipher
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sun.security.jsafe.RSACipher

java.lang.Object
   |
   +----sun.security.jsafe.RSACipher

public final class RSACipher
extends Object
RSA encryption and decryption, using PKCS #1 block types 01 and 02.

PKCS #1 can encrypt a variable number of bytes, ranging from one to k - 11 (where k is the modulus length in bytes). Padding is specified by the PKCS #1 algorithm, and the encrypted data is the same size as the modulus. With block type 02 (encrypt with public key, as for key exchange) that padding uses random data. In block type 01 (encrypt with the private key, as for digital signing) the padding is fixed data.

NOTE: This currently doesn't depend on features not in JDK 1.1, but the encryption API is modeled on the proposed encryption APIs that are currently unbundled from that release. It deletes most of the API and SPI calls, since they're not currently useful. At this time, it also draws an intialization-time distinction between two block types that those proposed encryption APIs only allow to be made by providing distinct ciphers.


Constructor Index

 o RSACipher()
Creates an uninitialized RSA cipher object.

Method Index

 o decryptAndUnpad(byte[])
Decrypt a PKCS #1 encrypted datum.
 o finalize()
Releases the BSAFE algorithm object used here.
 o initialize(Key, boolean)
Initializes the cipher object with a given key.
 o padAndEncrypt(byte[])
Encrypt a datum according to PKCS #1 padding and encryption rules.
 o toString()
Describes this cipher engine.

Constructors

 o RSACipher
  public RSACipher()
Creates an uninitialized RSA cipher object. This is associated with a BSAFE algorithm object.

Methods

 o initialize
  public void initialize(Key key,
                         boolean toEncrypt) throws InvalidKeyException
Initializes the cipher object with a given key.

NOTE: Strictly speaking, encrypting with a public key should provide a source of randomness; a default source is used when it's required.

Parameters:
key - the RSA key to be used.
toEncrypt - true iff the cipher object will encrypt.
 o padAndEncrypt
  public byte[] padAndEncrypt(byte plaintext[]) throws SecurityException
Encrypt a datum according to PKCS #1 padding and encryption rules.

Following this encryption, this cipher object may be used to perform more such encryptions.

Parameters:
plaintext - the unencrypted data, which may be at most eleven bytes smaller than the RSA modulus size of the key used.
Returns:
ciphertext, encrypted using PKCS #1
 o decryptAndUnpad
  public byte[] decryptAndUnpad(byte ciphertext[]) throws SecurityException
Decrypt a PKCS #1 encrypted datum.

Following this decryption, this cipher object may be used to perform more such decryptions.

Parameters:
ciphertext - PKCS #1 encrypted data in PKCS #1, which must be exactly as long as the RSA modulus being used.
Returns:
the plaintext corresponding to the ciphertext
 o toString
  public String toString()
Describes this cipher engine.
Overrides:
toString in class Object
 o finalize
  protected void finalize()
Releases the BSAFE algorithm object used here.
Overrides:
finalize in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index