edu.vt.middleware.crypt.symmetric
Class RC4

java.lang.Object
  extended by edu.vt.middleware.crypt.AbstractAlgorithm
      extended by edu.vt.middleware.crypt.AbstractEncryptionAlgorithm
          extended by edu.vt.middleware.crypt.symmetric.SymmetricAlgorithm
              extended by edu.vt.middleware.crypt.symmetric.RC4
All Implemented Interfaces:
Algorithm, EncryptionAlgorithm

public class RC4
extends SymmetricAlgorithm

Provider of symmetric encryption/decryption operations using RC4 cipher.

Version:
$Revision: 3 $
Author:
Middleware Services

Field Summary
static String ALGORITHM
          Algorithm name.
static int DEFAULT_KEY_LENGTH
          Default key size for this algorithm in bits.
static int[] KEY_LENGTHS
          Available key lengths in bits.
 
Fields inherited from class edu.vt.middleware.crypt.symmetric.SymmetricAlgorithm
DEFAULT_MODE, DEFAULT_PADDING, iv, paramSpec
 
Fields inherited from class edu.vt.middleware.crypt.AbstractEncryptionAlgorithm
cipher, cipherMode, key, mode, padding
 
Fields inherited from class edu.vt.middleware.crypt.AbstractAlgorithm
algorithm, logger, randomByteSize, randomProvider
 
Constructor Summary
RC4()
          Creates a RC4 symmetric encryption algorithm.
RC4(String mode, String padding)
          Creates a RC4 symmetric encryption algorithm.
 
Method Summary
 int[] getAllowedKeyLengths()
          Gets an array of key lengths that are acceptable for the cipher algorithm.
 int getDefaultKeyLength()
          Gets the default key length for this algorithm.
 boolean isValidKeyLength(int bitLength)
          Determines whether the given key size in bits is valid for this symmetric cipher algorithm.
 void setIV(byte[] ivBytes)
          Sets the encryption initialization vector.
 
Methods inherited from class edu.vt.middleware.crypt.symmetric.SymmetricAlgorithm
generateKey, generateKey, generateKey, getAlgorithmParameterSpec, getChunkSize, getMaxKeyLength, getMinKeyLength, getRandomIV, hasIV, newInstance, newInstance, newInstance, newInstance
 
Methods inherited from class edu.vt.middleware.crypt.AbstractEncryptionAlgorithm
crypt, crypt, decrypt, decrypt, decrypt, encrypt, encrypt, encrypt, getBlockSize, getCipherMode, getMode, getPadding, init, initCipher, initDecrypt, initEncrypt, setKey, toString
 
Methods inherited from class edu.vt.middleware.crypt.AbstractAlgorithm
getAlgorithm, getRandomData, setRandomProvider
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.vt.middleware.crypt.Algorithm
getAlgorithm, getRandomData, setRandomProvider
 

Field Detail

ALGORITHM

public static final String ALGORITHM
Algorithm name.

See Also:
Constant Field Values

DEFAULT_KEY_LENGTH

public static final int DEFAULT_KEY_LENGTH
Default key size for this algorithm in bits.

See Also:
Constant Field Values

KEY_LENGTHS

public static final int[] KEY_LENGTHS
Available key lengths in bits.

Constructor Detail

RC4

public RC4()
Creates a RC4 symmetric encryption algorithm.


RC4

public RC4(String mode,
           String padding)
Creates a RC4 symmetric encryption algorithm. The mode and padding arguments are ignored since this is a stream cipher and does not support a block mode or padding; it is provided for consistency with other ciphers only.

Parameters:
mode - Cipher mode name -- ignored.
padding - Cipher padding style name -- ignored.
Method Detail

setIV

public void setIV(byte[] ivBytes)
Sets the encryption initialization vector. A unique IV should be specified for each encryption operation using the same key for good security. Use the SymmetricAlgorithm.getRandomIV() method to obtain random initialization data of the appropriate size for the chosen cipher.

IV data is used upon calling either AbstractEncryptionAlgorithm.initEncrypt() or AbstractEncryptionAlgorithm.initDecrypt().

Overrides:
setIV in class SymmetricAlgorithm
Parameters:
ivBytes - Initialization bytes; in many cases the size of data should be equal to the cipher block size.

getDefaultKeyLength

public int getDefaultKeyLength()
Gets the default key length for this algorithm.

Overrides:
getDefaultKeyLength in class SymmetricAlgorithm
Returns:
Default key length in bits.

getAllowedKeyLengths

public int[] getAllowedKeyLengths()
Gets an array of key lengths that are acceptable for the cipher algorithm. By convention the lengths are returned in descending sort order from longest to shortest. There are some ciphers (e.g. Blowfish) that allow key sizes to be any integral value in a range; in those cases only key sizes that are multiple of the cipher block length are returned. Thus this method always returns lengths that are acceptable, but not necessarily all possible lengths.

Overrides:
getAllowedKeyLengths in class SymmetricAlgorithm
Returns:
Array of key lengths in bits.

isValidKeyLength

public boolean isValidKeyLength(int bitLength)
Determines whether the given key size in bits is valid for this symmetric cipher algorithm.

Overrides:
isValidKeyLength in class SymmetricAlgorithm
Parameters:
bitLength - Key size in bits.
Returns:
True if given value is a valid key size for this algorithm, false otherwise.


Copyright © 2003-2011 Virginia Tech. All Rights Reserved.