au.net.aba.crypto.provider
Class RC4

java.lang.Object
  |
  +--javax.crypto.CipherSpi
        |
        +--au.net.aba.crypto.provider.RC4

public class RC4
extends CipherSpi

A class that provides RC4 stream encryption.


Field Summary
static java.lang.String ident
           
 
Fields inherited from class javax.crypto.CipherSpi
ident
 
Constructor Summary
RC4()
           
 
Method Summary
 byte cipher(byte plainText)
          Encrypt the specified byte and return the encrypted byte.
protected  byte[] engineDoFinal(byte[] in, int inOff, int inLen)
          Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
protected  int engineDoFinal(byte[] in, int inOff, int inLen, byte[] out, int outOff)
          Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
protected  int engineGetBlockSize()
          Returns the block size (in bytes).
protected  byte[] engineGetIV()
          Returns the initialisation vector for this Cipher - in this case null
protected  int engineGetOutputSize(int inputLen)
          Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes).
protected  java.security.AlgorithmParameters engineGetParameters()
          Returns the parameters used with this cipher.
protected  void engineInit(int opMode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom rand)
          Initialises this cipher with a key and a source of randomness.
protected  void engineInit(int opMode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom rand)
          Initialises this cipher with a key and a source of randomness, using the AlgorithmParameters construct.
protected  void engineInit(int opMode, java.security.Key key, java.security.SecureRandom rand)
          Initialises this cipher with a key and a source of randomness.
 void engineSetMode(java.lang.String mode)
          Sets the mode of this cipher.
 void engineSetPadding(java.lang.String padding)
          Sets the padding mechanism of this cipher.
protected  byte[] engineUpdate(byte[] in, int inOff, int inLen)
          Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialised), processing another data part.
protected  int engineUpdate(byte[] in, int inOff, int inLen, byte[] out, int outOff)
          Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialised), processing another data part.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ident

public static final java.lang.String ident
Constructor Detail

RC4

public RC4()
Method Detail

engineInit

protected void engineInit(int opMode,
                          java.security.Key key,
                          java.security.SecureRandom rand)
                   throws java.security.InvalidKeyException
Initialises this cipher with a key and a source of randomness.
Overrides:
engineInit in class CipherSpi
Parameters:
opMode - the cipher mode.
key - the key to be used.
rand - the random number generator to be used.
Throws:
java.security.InvalidKeyException - if the key is of the wrong type.

engineInit

protected void engineInit(int opMode,
                          java.security.Key key,
                          java.security.spec.AlgorithmParameterSpec params,
                          java.security.SecureRandom rand)
                   throws java.security.InvalidKeyException
Initialises this cipher with a key and a source of randomness.
Overrides:
engineInit in class CipherSpi
Parameters:
opMode - the cipher mode.
key - the key to be used.
params - the parameter spec to be used.
rand - the random number generator to be used.
Throws:
java.security.InvalidKeyException - if the key is of the wrong type.

engineInit

protected void engineInit(int opMode,
                          java.security.Key key,
                          java.security.AlgorithmParameters params,
                          java.security.SecureRandom rand)
                   throws java.security.InvalidKeyException
Initialises this cipher with a key and a source of randomness, using the AlgorithmParameters construct.
Overrides:
engineInit in class CipherSpi
Parameters:
opMode - the cipher mode.
key - the key to be used.
params - the algorithm parameters to be used.
rand - the random number generator to be used.
Throws:
java.security.InvalidKeyException - if the key is of the wrong type.

engineGetIV

protected byte[] engineGetIV()
Returns the initialisation vector for this Cipher - in this case null
Overrides:
engineGetIV in class CipherSpi
Returns:
null

engineGetParameters

protected java.security.AlgorithmParameters engineGetParameters()
Returns the parameters used with this cipher.
Overrides:
engineGetParameters in class CipherSpi
Returns:
the algorithm parameters.

engineSetMode

public void engineSetMode(java.lang.String mode)
                   throws java.security.NoSuchAlgorithmException
Sets the mode of this cipher. Accepts ECB only.
Overrides:
engineSetMode in class CipherSpi
Parameters:
mode - the mode we want.
Throws:
java.security.NoSuchAlgorithmException - The mode is not ECB.

engineSetPadding

public void engineSetPadding(java.lang.String padding)
                      throws NoSuchPaddingException
Sets the padding mechanism of this cipher. Accepts NoPadding only.
Overrides:
engineSetPadding in class CipherSpi
Parameters:
padding - the type of padding we want.
Throws:
NoSuchPaddingException - The padding is not "NoPadding".

engineGetBlockSize

protected int engineGetBlockSize()
Returns the block size (in bytes).
Overrides:
engineGetBlockSize in class CipherSpi
Returns:
the block size (in bytes), or 0 if the underlying algorithm is not a block cipher

engineGetOutputSize

protected int engineGetOutputSize(int inputLen)
Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes).
Overrides:
engineGetOutputSize in class CipherSpi
Parameters:
inputLen - the length of bytes we are planning to input.
Returns:
the output size for input bytes plus what is in the buffer.

engineUpdate

protected byte[] engineUpdate(byte[] in,
                              int inOff,
                              int inLen)
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialised), processing another data part. Returns null if cipher didn't receive enough data.
Overrides:
engineUpdate in class CipherSpi
Parameters:
in - the data to be processed.
inOff - the offset in the in array that processing should start from.
inLen - the number of bytes of data to be processed.
Returns:
the resulting data (null if more is required).

engineUpdate

protected int engineUpdate(byte[] in,
                           int inOff,
                           int inLen,
                           byte[] out,
                           int outOff)
                    throws ShortBufferException
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialised), processing another data part.
Overrides:
engineUpdate in class CipherSpi
Parameters:
in - the data to be processed.
inOff - the offset in the in array that processing should start from.
inLen - the number of bytes of data to be processed.
out - the array that the output is to be put into.
outOff - the offset in the out array that processed data should start being written at.
Returns:
the number of bytes that were output to the out array.
Throws:
ShortBufferException - The provided output buffer is too short.

engineDoFinal

protected byte[] engineDoFinal(byte[] in,
                               int inOff,
                               int inLen)
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this cipher was initialised.
Overrides:
engineDoFinal in class CipherSpi
Parameters:
in - the data to be processed.
inOff - the offset in the in array that processing should start from.
inLen - the number of bytes of data to be processed.
Returns:
the resulting data (null if there isn't enough).

engineDoFinal

protected int engineDoFinal(byte[] in,
                            int inOff,
                            int inLen,
                            byte[] out,
                            int outOff)
                     throws ShortBufferException
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
Overrides:
engineDoFinal in class CipherSpi
Parameters:
in - the data to be processed.
inOff - the offset in the in array that processing should start from.
inLen - the number of bytes of data to be processed.
out - the array that the output is to be put into.
outOff - the offset in the out array that processed data should start being written at.
Returns:
the number of bytes that were output to the out array.
Throws:
ShortBufferException - The provided output buffer is too small for the decrypted result.

cipher

public byte cipher(byte plainText)
Encrypt the specified byte and return the encrypted byte.
Parameters:
plainText - The plain text data.
Returns:
The encrypted data.