iaik.me.security.cipher
Class ARCFOUR

java.lang.Object
  |
  +--iaik.me.security.Cipher
        |
        +--iaik.me.security.cipher.ARCFOUR

public final class ARCFOUR
extends Cipher

This class implements the ARCFOUR cipher as specified by the IETF draft "A Stream Cipher Encryption Algorithm 'Arcfour'" (draft-kaukonen-cipher-arcfour-03.txt). It is believed to be compatible with RC4[TM] (described for example in Bruce Schneierīs Applied Cryptography), a proprietary cipher of RSA Security Inc.

The ARCFOUR algorithm is a stream cipher using a key of variable size.

Applications shall preferable use the Cipher.getInstance(String) method from the Cipher class:

 byte[] keydata = .....
 CryptoBag key = CryptoBag.makeSecretKey(keydata);
 Cipher cipher = Cipher.getInstance("ARCFOUR");
 cipher.init(Cipher.ENCRYPT_MODE, key);
 byte[] ciphertext = cipher.doFinal(data); 
 cipher.init(Cipher.DECRYPT_MODE, key);
 data = cipher.doFinal(ciphertext);
 
For compatibility reasons, the alias RC4 is still supported.

Since:
3.0
See Also:
Cipher

Fields inherited from class iaik.me.security.Cipher
chainingMode, DECRYPT_MODE, ENCRYPT_MODE, iv, mode, MODE_CBC, MODE_ECB
 
Constructor Summary
ARCFOUR()
          Constructor for the ARCFOUR cipher.
 
Method Summary
 int[] getKeyLength()
          Returns information about the ARCFOUR key lenghts.
[0] is the minumum keykength (8 bit for ARCFOUR)
[1] is the recommended default length (128 bit).
 void init(int mode, CryptoBag keyb, Object params, SecureRandom random)
          Initializes this ARCFOUR cipher with proper key and algorithm parameters, and some random seed.
 int update(byte[] in, int inOff, int inLen, byte[] out, int outOff)
          Encrypts the given data bytes using the ARCFOUR algorithm.
protected  int updateInternal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset, boolean doFinal)
          This is method performs the actual en-/decipher opertion.
 
Methods inherited from class iaik.me.security.Cipher
cryptBlock, doFinal, doFinal, extractIV, getBlockSize, getInstance, getIV, init, register, setMode, setPadding, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ARCFOUR

public ARCFOUR()
Constructor for the ARCFOUR cipher. This constructor is only internally used for initializing a ARCFOUR Cipher. Applications should not call this constructor to get a ARCFOUR Cipher; they should call the Cipher.getInstance(String) factory method. instead.
Since:
3.0
Method Detail

getKeyLength

public int[] getKeyLength()
Returns information about the ARCFOUR key lenghts.
[0] is the minumum keykength (8 bit for ARCFOUR)
[1] is the recommended default length (128 bit).
[2] is the maximum allowable length (1024 bit).
[3] increment between key length (8 bit)
Overrides:
getKeyLength in class Cipher
Returns:
an integer array containing the various keylengths
Since:
3.0
See Also:
Cipher.getKeyLength()

init

public void init(int mode,
                 CryptoBag keyb,
                 Object params,
                 SecureRandom random)
          throws CryptoException
Initializes this ARCFOUR cipher with proper key and algorithm parameters, and some random seed. Before a cipher object is ready for data processing, it has to be initialized according to the desired cryptographic operation, which is specified by the opmode parameter (either ENCRYPT_MODE or DECCRYPT_MODE).

The format of the key must be "RAW". An initialisation call may look like this:

Cipher cipher = Cipher.getInstance("ARCFOUR");
cipher.init(Cipher.ENCRYPT_MODE, key);

or
cipher.init(Cipher.ENCRYPT_MODE, key, null, null);

Overrides:
init in class Cipher
Parameters:
mode - the operation mode for which this cipher is used (ENCRYPT_MODE or DECRYPT_MODE)
keyb - a CryptoBag containing the secret key
params - the algorithm parameters (Actually this parameter is ignored as the ARCFOUR does not need additional parameters. For this reason, the parameter can be set to null)
random - the random seed (Actually this parameter is ignored as the ARCFOUR does not need additional parameters. For this reason, the paramter can be set to null)
Throws:
InvalidKeyException - if the key is invalid
Since:
3.0

update

public int update(byte[] in,
                  int inOff,
                  int inLen,
                  byte[] out,
                  int outOff)
           throws CryptoException
Encrypts the given data bytes using the ARCFOUR algorithm. The same as decrypt. The data to be processed is given in an input byte array. Beginning at inOff, only the first inLen bytes are encrypted. The result is stored within the given output byte array, beginning at outOff.
Overrides:
update in class Cipher
Parameters:
in - the input data
inOff - the offset indicating where the subarray starts in the in array
inLen - the length of the subarray
out - the output buffer.
outOff - the offset indicating where to start writing the result into the output buffer
Returns:
the number of bytes that were handed over by the parameter inLen
Throws:
CryptoException -  
Since:
3.0

updateInternal

protected int updateInternal(byte[] input,
                             int inputOffset,
                             int inputLen,
                             byte[] output,
                             int outputOffset,
                             boolean doFinal)
                      throws CryptoException
Description copied from class: Cipher
This is method performs the actual en-/decipher opertion. The method always buffers the last block of the operation. The block is returned by the doFinal() operation. The doFinal flag indicates whether to return this block (doFinal() was invoked) or hold it for the next call (update() was invoked.
Overrides:
updateInternal in class Cipher
Following copied from class: iaik.me.security.Cipher
Parameters:
input - input data
inputOffset - offset from which on the input data will be processed
inputLen - length of the input data that will be processed
output - the processed input data
outputOffset -  
doFinal - flag indicates whether this method was invoked from Cipher.update or Cipher.doFinal
Returns:
number of blocks processed
Throws:
CryptoException - is thrown if an error occurs during cipher operation

This Javadoc may contain text parts from IETF Internet Standard specifications, see copyright note) and RSA Data Security Public-Key Cryptography Standards (see copyright note).

IAIK-JCE ME 3.04, (c) 2002 IAIK, (c) 2003 to 2006 Stiftung SIC