com.rsa.jsafe
Class JSAFE_Recode

java.lang.Object
  extended bycom.rsa.jsafe.JSAFE_Object
      extended bycom.rsa.jsafe.JSAFE_Recode
All Implemented Interfaces:
Cloneable, Serializable

public abstract class JSAFE_Recode
extends JSAFE_Object

The JSAFE_Recode class changes the encoding of data from binary to ASCII and vice versa. Crypto-J currently supports Base64-encoding. This class can instantiate the classes that create and verify signatures, and it defines the functionality.

See Overview of Crypto-J for background and reference material on using and understanding Crypto-J.

Copyright © RSA Security Inc., 1997-2005. All rights reserved.

See Also:
Serialized Form

Constructor Summary
JSAFE_Recode()

 

 
Method Summary

 void

clearSensitiveData()

Clears sensitive data from an object.

 byte[]

decodeFinal()

Finalizes the decoding and strips the padding, if necessary.

abstract  int

decodeFinal(byte[] partOut, int outOffset)

Finalizes the process and decodes any leftover bytes.

abstract  void

decodeInit()

Initializes this object to perform decoding.

 byte[]

decodeUpdate(byte[] partIn, int inOffset, int partInLen)

Decodes the first partInLen bytes in the array partIn, beginning at inOffset.

abstract  int

decodeUpdate(byte[] partIn, int inOffset, int partInLen, byte[] partOut, int outOffset)

Decodes the first partInLen bytes in the array partIn, beginning at inOffset.

 byte[]

encodeFinal()

Finalizes the encoding process and encodes any leftover bytes.

abstract  int

encodeFinal(byte[] partOut, int outOffset)

Finalizes the encoding, appending the padding if necessary.

abstract  void

encodeInit()

Initializes this object to encode.

 byte[]

encodeUpdate(byte[] partIn, int inOffset, int partInLen)

Encodes the input data.

abstract  int

encodeUpdate(byte[] partIn, int inOffset, int partInLen, byte[] partOut, int outOffset)

Encodes the first partInLen bytes in the array partIn, beginning at inOffset.

abstract  String

getAlgorithm()

Returns the standard recode algorithm name.

abstract  int[]

getAlgorithmParameters()

Returns a new int array containing the algorithm's parameters.

 String

getDevice()

Returns the name of the device of record.

 String[]

getDeviceList()

Returns a String array that describes all the devices used to execute the transformation.

static JSAFE_Recode

getInstance(String transformation, String device)

Builds an object that performs the transformation on the given device.

abstract  int

getOutputBufferSize(int inputLen)

Returns the maximum size (in bytes) that an output buffer should be to hold the results of an encode or a decode (Update and Final).

 
Methods inherited from class com.rsa.jsafe.JSAFE_Object
clone, overwrite, overwrite
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSAFE_Recode

public JSAFE_Recode()
Method Detail

getInstance

public static JSAFE_Recode getInstance(String transformation,
                                       String device)
                                throws JSAFE_UnimplementedException,
                                       JSAFE_InvalidParameterException
Builds an object that performs the transformation on the given device.

The value of transformation is as follows:
transformation ValueDescription
"Base64-sWhere s is the encoded line size (default is 76). (0 < s <= 76, s must be a multiple of 4).

The value of device is as follows: "choice1[/choice2[...[/choicen]]]".

The device values are:

Crypto-J tries to instantiate a class using the first choice. If it cannot, it tries the other choices. The following example performs Base64-encoding or recoding without inserted CR or LF breaks, using Java.

JSAFE_Recode recode =
   JSAFE_Recode.getInstance
     ("Base64-0", "Java");
The following example performs Base64-encoding using the default encoded line size of 76 characters, using Java.
JSAFE_Recode recode =
   JSAFE_Recode.getInstance
     ("Base64", "Java");
 

Parameters:
transformation - The representation of the desired operation (for example, "Base64").
device - A list of devices used to build the object (for example, "Java", "Native/Java").
Returns:
A new JSAFE_Recode object that performs the transformation.
Throws:
JSAFE_UnimplementedException - If the device or devices cannot perform the designated algorithm.
JSAFE_InvalidParameterException - If the specified transformation contains parameters that do not work.

getDevice

public String getDevice()
Returns the name of the device of record. Possible device values are:

Returns:
The device name.

getDeviceList

public String[] getDeviceList()
Returns a String array that describes all the devices used to execute the transformation. Because a transformation often consists of component algorithms, the implementation can consist of several component Objects. A device can perform one or more of the algorithms, but it may let Java or another device perform one or more. For example, because padding is not time-consuming, a device might let the Crypto-J implementation perform padding. Returns the names of the devices used by each component.

Returns:
A String array that describes the device used for a specific component.

getAlgorithm

public abstract String getAlgorithm()
Returns the standard recode algorithm name.

Returns:
A String that describes the recode algorithm.

getAlgorithmParameters

public abstract int[] getAlgorithmParameters()
Returns a new int array containing the algorithm's parameters. For example, if the underlying algorithm is Base64-76, the return value is an array of length 1, containing the encoded line size. If the algorithm is Base64, the return value is a zero-element array because no arguments are specified.

This may be an array of length 0.

Returns:
A new int array containing the parameters of the algorithm.

getOutputBufferSize

public abstract int getOutputBufferSize(int inputLen)
Returns the maximum size (in bytes) that an output buffer should be to hold the results of an encode or a decode (Update and Final). The computation includes the length of any unprocessed data. However, the actual output may be smaller than the reported value. Given the length of input bytes (inputLen).

Parameters:
inputLen - The length of the input in bytes.
Returns:
An int that indicates the size of the output. If the object has not been initialized yet, this method returns -1.

encodeInit

public abstract void encodeInit()
                         throws JSAFE_InvalidUseException
Initializes this object to encode.

Throws:
JSAFE_InvalidUseException - If the object cannot be initialized.

encodeUpdate

public byte[] encodeUpdate(byte[] partIn,
                           int inOffset,
                           int partInLen)
                    throws JSAFE_InvalidUseException
Encodes the input data. This method encodes the first partInLen bytes in the array partIn, beginning at inOffset. It returns the result in the byte array partOut.

Parameters:
partIn - The data to encode.
inOffset - The offset into partIn where the data begins.
partInLen - The length of the data to encode.
Returns:
A new byte array containing the encoded data.
Throws:
JSAFE_InvalidUseException - If the object is not initialized to encode.

encodeUpdate

public abstract int encodeUpdate(byte[] partIn,
                                 int inOffset,
                                 int partInLen,
                                 byte[] partOut,
                                 int outOffset)
                          throws JSAFE_InvalidUseException
Encodes the first partInLen bytes in the array partIn, beginning at inOffset. It returns the result in the byte array partOut, beginning at outOffset.

Parameters:
partIn - The data to encode.
inOffset - The offset into partIn where the data begins.
partInLen - The length of the data to encode.
partOut - The buffer where the output is placed.
outOffset - The offset into partOut where the writing begins.
Returns:
The number of bytes placed into the output buffer.
Throws:
JSAFE_InvalidUseException - If the object is not initialized to encode.

encodeFinal

public byte[] encodeFinal()
                   throws JSAFE_InvalidUseException,
                          JSAFE_InputException
Finalizes the encoding process and encodes any leftover bytes. It returns the result in a new byte array. A Final method must be called before reusing an object to encode or to decode.

Returns:
A new byte array containing the encoded data.
Throws:
JSAFE_InvalidUseException - If the object is not initialized to encode.
JSAFE_InputException - If the input was not padded.

encodeFinal

public abstract int encodeFinal(byte[] partOut,
                                int outOffset)
                         throws JSAFE_InvalidUseException
Finalizes the encoding, appending the padding if necessary. Encodes any leftover bytes. Places the result into the byte array partOut, beginning at outOffset. The return value is the number of bytes placed in the output buffer. A Final method must be called before reusing an object to encode or to decode.

Parameters:
partOut - The buffer where the output is placed.
outOffset - The offset into partOut where the writing begins.
Returns:
The number of bytes placed into the output buffer.
Throws:
JSAFE_InvalidUseException - If the object is not initialized to encode.

decodeInit

public abstract void decodeInit()
                         throws JSAFE_InvalidUseException
Initializes this object to perform decoding.

Throws:
JSAFE_InvalidUseException - If the object cannot be initialized.

decodeUpdate

public byte[] decodeUpdate(byte[] partIn,
                           int inOffset,
                           int partInLen)
                    throws JSAFE_InvalidUseException,
                           JSAFE_InputException
Decodes the first partInLen bytes in the array partIn, beginning at inOffset. Decodes the input data. Returns the result in a new byte array.

Parameters:
partIn - The data to decode.
inOffset - The offset into partIn where the data begins.
partInLen - The length of the data to decode.
Returns:
A new byte array containing the encoded data.
Throws:
JSAFE_InvalidUseException - If the object is not initialized to decode.
JSAFE_InputException

decodeUpdate

public abstract int decodeUpdate(byte[] partIn,
                                 int inOffset,
                                 int partInLen,
                                 byte[] partOut,
                                 int outOffset)
                          throws JSAFE_InvalidUseException,
                                 JSAFE_InputException
Decodes the first partInLen bytes in the array partIn, beginning at inOffset. Decodes the input data. Returns the result in the byte array partOut, beginning at outOffset. The return value is the number of bytes placed in the output buffer.

Parameters:
partIn - The data to decode.
inOffset - The offset into partIn where the data begins.
partInLen - The length of the data to decode.
partOut - The buffer where the output is placed.
outOffset - The offset into partOut where the writing begins.
Returns:
The number of bytes placed into the output buffer.
Throws:
JSAFE_InvalidUseException - If the object is not initialized to decode.
JSAFE_InputException

decodeFinal

public byte[] decodeFinal()
                   throws JSAFE_InvalidUseException,
                          JSAFE_InputException
Finalizes the decoding and strips the padding, if necessary. Returns the result (if any) in a new byte array. If there are no output bytes, it returns a zero-length array. A Final method must be called before reusing an object to encode or decode.

Returns:
A new byte array containing the decoded data.
Throws:
JSAFE_InvalidUseException - If the object is not initialized to decode.
JSAFE_InputException - If the input could not be unpadded.

decodeFinal

public abstract int decodeFinal(byte[] partOut,
                                int outOffset)
                         throws JSAFE_InvalidUseException,
                                JSAFE_InputException
Finalizes the process and decodes any leftover bytes. Returns the result (if any) in the byte array partOut, beginning at outOffset. The return value is the number of bytes actually placed in the output buffer. If there are no output bytes, returns null. A Final method must be called before reusing the object to encode or decode.

Parameters:
partOut - The buffer where the output is placed.
outOffset - The offset into partOut where the writing begins.
Returns:
The number of bytes placed into the output buffer.
Throws:
JSAFE_InvalidUseException - If the object is not initialized to decode.
JSAFE_InputException - If the input could not be unpadded.

clearSensitiveData

public void clearSensitiveData()
Clears sensitive data from an object. Although the finalizer clears the data, there is no guarantee the garbage collector will quickly call the finalizer. Allows a user to clear data as soon as possible. After calling clearSensitiveData(), an Init (not a ReInit) method is called to perform other operations with the object.



RSA BSAFE Crypto-J 3.5.2