com.cafesoft.core.crypto
Interface SymmetricCipher

All Known Implementing Classes:
SecretKeyCipher

public interface SymmetricCipher

SymmetricCipher defines an interface for encrypting and decrypting data based on symmetric algorithms. Implementations may use a secret key, public/private key, etc. as required.


Method Summary
 byte[] decrypt(byte[] input)
          Decrypts data in a single-part operation.
 int decrypt(byte[] input, int inputLen, byte[] output)
          Decrypts data in a single-part operation.
 byte[] encrypt(byte[] input)
          Encrypts data in a single-part operation.
 int encrypt(byte[] input, int inputLen, byte[] output)
          Encrypts data in a single-part operation.
 

Method Detail

encrypt

public byte[] encrypt(byte[] input)
               throws IllegalStateException,
                      IllegalBlockSizeException,
                      BadPaddingException
Encrypts data in a single-part operation.

The bytes in the input buffer are processed and padded if necessary. The result is stored in a new buffer.

Parameters:
input - the input buffer
Returns:
the new buffer with the result
Throws:
IllegalStateException - if this cipher is in a wrong state (e.g., has not been initialized)
IllegalBlockSizeException - - if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size
BadPaddingException - if the internal encryption cipher has and invalid padding configuration or has an error while padding data.

encrypt

public int encrypt(byte[] input,
                   int inputLen,
                   byte[] output)
            throws IllegalStateException,
                   IllegalBlockSizeException,
                   ShortBufferException,
                   BadPaddingException
Encrypts data in a single-part operation.

The specified number of bytes in the input buffer are processed and padded if necessary. The result is stored in the specified output buffer. NOTE: this method should be used in preference to methods that return new byte buffers when multiple encrptions must be performed within the scope of a calling method. This enables reuse of the output buffer for returned encrypted cipher text.

Parameters:
input - the input buffer (the clear text)
inputLen - the number of bytes to be read from the input buffer
output - the output buffer (for storing cipher text)
Returns:
the number of byte written to the output buffer or 0 if no bytes encrypted.
Throws:
IllegalStateException - if this cipher is in a wrong state (e.g., has not been initialized)
ShortBufferException - if the given output buffer is too small to hold the result
IllegalBlockSizeException - - if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size
BadPaddingException - if the internal encryption cipher has and invalid padding configuration or has an error while padding data.

decrypt

public byte[] decrypt(byte[] input)
               throws IllegalStateException,
                      IllegalBlockSizeException,
                      BadPaddingException
Decrypts data in a single-part operation.

The bytes in the input buffer are processed and padding that was added at encryption time is removed. The result is stored in a new buffer.

Parameters:
input - the input buffer
Returns:
the new buffer with the result
Throws:
IllegalStateException - if this cipher is in a wrong state (e.g., has not been initialized)
IllegalBlockSizeException - - if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size
BadPaddingException - if the internal encryption cipher has and invalid padding configuration or has an error while padding data.

decrypt

public int decrypt(byte[] input,
                   int inputLen,
                   byte[] output)
            throws IllegalStateException,
                   IllegalBlockSizeException,
                   ShortBufferException,
                   BadPaddingException
Decrypts data in a single-part operation.

The specified number of bytes in the input buffer are processed and padding is removed. The result is stored in the specified output buffer. NOTE: this method should be used in preference to methods that return new byte buffers when multiple decryptions must be performed within the scope of a calling method. This enables reuse of the output buffer for returned decrypted clear text.

Parameters:
input - the input buffer (the cipher text)
inputLen - the number of bytes to be read from the input buffer
output - the output buffer (for storing clear text)
Returns:
the number of byte written to the output buffer or 0 if no bytes encrypted.
Throws:
IllegalStateException - if this cipher is in a wrong state (e.g., has not been initialized)
ShortBufferException - if the given output buffer is too small to hold the result
IllegalBlockSizeException - - if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size
BadPaddingException - if the internal encryption cipher has and invalid padding configuration or has an error while padding data.


Generated on 10:40:31 AM September 10, 2003, © 1996-2003 Cafésoft LLC. All rights reserved.