/*
 * $Id$
 * 
 * This file is provided under the standard terms of the Artistic Licence.  See the
 * LICENSE file that comes with this package for details.
 */
package org.pwsafe.lib.crypto;

import org.pwsafe.lib.Util;

import BlowfishJ.BlowfishCBC;

/**
 * An extension to the BlowfishJ.BlowfishCBC to allow it to be used for PasswordSafe. Byte 
 * order differences prevent BlowfishCBC being used directly.
 * 
 * @author Kevin Preece
 */
public class BlowfishPws extends BlowfishCBC
{
	/**
	 * Constructor, sets the initial vector to zero.
	 * 
	 * @param bfkey the encryption/decryption key.
	 */
	public BlowfishPws( byte[] bfkey )
	{
		super(bfkey, 0, bfkey.length);
	}

	/**
	 * Constructor, sets the initial vector to the value given.
	 * 
	 * @param bfkey      the encryption/decryption key.
	 * @param lInitCBCIV the initial vector.
	 */
	public BlowfishPws( byte[] bfkey, long lInitCBCIV )
	{
		super(bfkey, 0, bfkey.length, lInitCBCIV);
	}

	/**
	 * Constructor, sets the initial vector to the value given.
	 * 
	 * @param bfkey      the encryption/decryption key.
	 * @param initCBCIV the initial vector.
	 */
	public BlowfishPws( byte[] bfkey, byte[] initCBCIV )
	{
		super( bfkey, 0, bfkey.length );
		setCBCIV( initCBCIV );
	}

	/**
	 * Decrypts <code>buffer</code> in place.
	 * 
	 * @param buffer the buffer to be decrypted.
	 * 
	 * @see BlowfishJ.BlowfishCBC#decrypt
	 */
	public void decrypt( byte[] buffer )
	{
		Util.bytesToLittleEndian( buffer );
		super.decrypt( buffer, 0, buffer, 0, buffer.length );
		Util.bytesToLittleEndian( buffer );
	}

//	/**
//	 * Decrypts the data in <code>inbuffer</code> putting the decrypted data into
//	 * <code>outbuffer</code>.
//	 * <p />
//	 * @param inbuffer  the buffer containing the encrypted data.
//	 * @param outbuffer the buffer to receive the decrypted data.
//	 */
//	public void decrypt( byte[] inbuffer, byte [] outbuffer )
//	{
//		System.arraycopy( inbuffer, 0, outbuffer, 0, inbuffer.length );
//		this.decrypt( outbuffer );
//	}

	/**
	 * Encrypts <code>buffer</code> in place.
	 * 
	 * @param buffer the buffer to be encrypted.
	 * 
	 * @see BlowfishJ.BlowfishCBC#encrypt(byte[])
	 */
	public void encrypt( byte[] buffer )
	{
		Util.bytesToLittleEndian( buffer );
		super.encrypt(buffer, 0, buffer, 0, buffer.length);
		Util.bytesToLittleEndian( buffer );
	}

	/**
	 * Sets the initial vector.
	 * 
	 * @param newCBCIV the new value for the initial vector.
	 */
	public void setCBCIV( byte[] newCBCIV )
	{
		byte temp[] = new byte [ newCBCIV.length ];
		System.arraycopy( newCBCIV, 0, temp, 0, newCBCIV.length );
		Util.bytesToLittleEndian( temp );
		super.setCBCIV( temp, 0 );
	}

}

@@ -1342,52 +1342,8 @@
 ed.%0A
-%09 * %0A%09 * @see BlowfishJ.BlowfishCBC#decrypt%0A
 %09 */
@@ -1524,446 +1524,8 @@
 %09%7D%0A%0A
-//%09/**%0A//%09 * Decrypts the data in %3Ccode%3Einbuffer%3C/code%3E putting the decrypted data into%0A//%09 * %3Ccode%3Eoutbuffer%3C/code%3E.%0A//%09 * %3Cp /%3E%0A//%09 * @param inbuffer  the buffer containing the encrypted data.%0A//%09 * @param outbuffer the buffer to receive the decrypted data.%0A//%09 */%0A//%09public void decrypt( byte%5B%5D inbuffer, byte %5B%5D outbuffer )%0A//%09%7B%0A//%09%09System.arraycopy( inbuffer, 0, outbuffer, 0, inbuffer.length );%0A//%09%09this.decrypt( outbuffer );%0A//%09%7D%0A%0A
 %09/**
@@ -1623,60 +1623,8 @@
 ed.%0A
-%09 * %0A%09 * @see BlowfishJ.BlowfishCBC#encrypt(byte%5B%5D)%0A
 %09 */

Remove redundant methods, update javadoc comments