//============================================================================== // NullCipher.java //============================================================================== package tribble.crypto; // System imports import java.lang.Exception; import java.lang.String; import java.lang.System; import java.security.InvalidKeyException; import java.security.Key; // Local imports import tribble.crypto.SymmetricCipher; /******************************************************************************* * Null block cipher. * Implements a symmetric block cipher that does not actually perform any * encrypting or decrypting (i.e., it simply copies each input block to its * output). * * * @version $Revision: 1.2 $ $Date: 2005/07/06 03:09:00 $ * @since 2005-04-25 * @author * David R. Tribble * (david@tribble.com). * *

* Copyright ©2005 by David R. Tribble, all rights reserved. *
* Permission is granted to freely use and distribute this source code * provided that the original copyright and authorship notices remain * intact. */ public final class NullCipher extends tribble.crypto.SymmetricCipher { // Identification /** Revision information. */ static final String REV = "@(#)tribble/crypto/NullCipher.java $Revision: 1.2 $ $Date: 2005/07/06 03:09:00 $\n"; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Private constants /** Algorithm name. */ private static final String ALGORITHM = "Null"; /** Block size, in bytes. */ private static final int BLOCK_SIZE = 8; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Variables // (None) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Public constructors /*************************************************************************** * Default constructor. * * @since 1.1, 2005-07-05 */ public NullCipher() { // Initialize super(ALGORITHM, BLOCK_SIZE); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Protected methods /*************************************************************************** * Initialize this cipher. * * @param key * The symmetric (secret) key for this cipher. * * @param decrypt * If true, this indicates that this cipher is to be initialized for * decrypting, otherwise it is to be initialized for encrypting. * * @since 1.1, 2005-07-05 */ protected void initialize(byte[] key, boolean decrypt) throws InvalidKeyException //overrides tribble.crypto.SymmetricCipher { // Initialize m_keyLen = (key != null ? key.length : 0); m_decrypt = decrypt; } /*************************************************************************** * Reset this cipher, wiping all sensitive information. * *

* This method will be called after this cipher object is no longer needed. * It should overwrite any sensitive data contained within this object * (e.g., encryption key schedules). * This cipher object can no longer be used after this method has been * called. * * @see #initialize initialize() * * @since 1.1, 2005-07-05 */ protected void clear() //overrides tribble.crypto.SymmetricCipher { // This cipher algorithm does nothing } /*************************************************************************** * Encrypt a block of plaintext. * * @param in * Array containing a single block of plaintext bytes to encrypt. * The length of the block is exactly equal to the cipher block size. * * @param inOff * Index of the first byte of the plaintext block within array in to * encrypt. * * @param out * Array that will be filled with the encrypted ciphertext block. * The length of the block is exactly equal to the cipher block size. * * @param outOff * Index of the first byte of array out to fill with the encrypted * ciphertext block. * * @see #blockDecrypt * * @since 1.1, 2005-07-05 */ protected void blockEncrypt(/*const*/ byte[] in, int inOff, byte[] out, int outOff) //overrides tribble.crypto.SymmetricCipher { // This cipher algorithm does nothing for (int i = BLOCK_SIZE; i > 0; i--) out[outOff++] = in[inOff++]; } /*************************************************************************** * Decrypt a block of ciphertext. * * @param in * Array containing a single block of ciphertext bytes to decrypt. * The length of the block is exactly equal to the cipher block size. * * @param inOff * Index of the first byte of the ciphertext block within array in * to decrypt. * * @param out * Array that will be filled with the decrypted plaintext block. * The length of the block is exactly equal to the cipher block size. * * @param outOff * Index of the first byte of array out to fill with the decrypted * plaintext block. * * @see #blockEncrypt * * @since 1.1, 2005-07-05 */ protected void blockDecrypt(/*const*/ byte[] in, int inOff, byte[] out, int outOff) //overrides tribble.crypto.SymmetricCipher { // This cipher algorithm does nothing for (int i = BLOCK_SIZE; i > 0; i--) out[outOff++] = in[inOff++]; } } // End NullCipher.java