edu.vt.middleware.crypt.pbe
Class AbstractEncryptionScheme

java.lang.Object
  extended by edu.vt.middleware.crypt.pbe.AbstractEncryptionScheme
All Implemented Interfaces:
EncryptionScheme
Direct Known Subclasses:
AbstractVariableKeySizeEncryptionScheme, PBES1EncryptionScheme

public abstract class AbstractEncryptionScheme
extends Object
implements EncryptionScheme

Abstract base class for password-based encryption schemes based on salt data and iterated hashing as the basis of the key derivation function.

NOTE: Classes derived from this class are not thread safe. In particular, care should be take to prevent multiple threads from performing encryption and/or decryption concurrently.

Version:
$Revision: 2744 $
Author:
Middleware Services

Field Summary
protected  SymmetricAlgorithm cipher
          Cipher used for encryption and decryption.
 
Constructor Summary
AbstractEncryptionScheme()
           
 
Method Summary
 byte[] decrypt(char[] password, byte[] ciphertext)
          Decrypts the given ciphertext bytes into a byte array of plaintext using a decryption key based on the given password.
 void decrypt(char[] password, InputStream in, OutputStream out)
          Decrypts the data in the given ciphertext input stream into plaintext in the output stream.
 byte[] encrypt(char[] password, byte[] plaintext)
          Encrypts the given plaintext bytes into a byte array of ciphertext using an encryption key derived from the password.
 void encrypt(char[] password, InputStream in, OutputStream out)
          Encrypts the data in the given plaintext input stream into ciphertext in the output stream.
protected abstract  void initCipher(char[] password)
          Initializes the cipher with the given PBE derived key bytes.
protected  void setCipher(SymmetricAlgorithm alg)
          Sets the symmetric algorithm cipher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cipher

protected SymmetricAlgorithm cipher
Cipher used for encryption and decryption.

Constructor Detail

AbstractEncryptionScheme

public AbstractEncryptionScheme()
Method Detail

encrypt

public byte[] encrypt(char[] password,
                      byte[] plaintext)
               throws CryptException
Encrypts the given plaintext bytes into a byte array of ciphertext using an encryption key derived from the password.

Specified by:
encrypt in interface EncryptionScheme
Parameters:
password - Basis for encryption.
plaintext - Input plaintext bytes.
Returns:
Ciphertext resulting from plaintext encryption.
Throws:
CryptException - On encryption errors.

encrypt

public void encrypt(char[] password,
                    InputStream in,
                    OutputStream out)
             throws CryptException,
                    IOException
Encrypts the data in the given plaintext input stream into ciphertext in the output stream. Use Base64FilterOutputStream or HexFilterOutputStream to produce ciphertext in the output stream in an encoded string repreprestation.

Specified by:
encrypt in interface EncryptionScheme
Parameters:
password - Basis for encryption.
in - Input stream of plaintext.
out - Output stream of ciphertext.
Throws:
CryptException - On encryption errors.
IOException - On stream read/write errors.

decrypt

public byte[] decrypt(char[] password,
                      byte[] ciphertext)
               throws CryptException
Decrypts the given ciphertext bytes into a byte array of plaintext using a decryption key based on the given password.

Specified by:
decrypt in interface EncryptionScheme
Parameters:
password - Basis for encryption.
ciphertext - Input ciphertext bytes.
Returns:
Plaintext resulting from ciphertext decryption.
Throws:
CryptException - On decryption errors.

decrypt

public void decrypt(char[] password,
                    InputStream in,
                    OutputStream out)
             throws CryptException,
                    IOException
Decrypts the data in the given ciphertext input stream into plaintext in the output stream. Use Base64FilterInputStream or HexFilterInputStream to consume ciphertext in an encoded string representation.

Specified by:
decrypt in interface EncryptionScheme
Parameters:
password - Basis for encryption.
in - Input stream of ciphertext.
out - Output stream of plaintext.
Throws:
CryptException - On decryption errors.
IOException - On stream read/write errors.

setCipher

protected void setCipher(SymmetricAlgorithm alg)
Sets the symmetric algorithm cipher.

Parameters:
alg - Symmetric algorithm instance.

initCipher

protected abstract void initCipher(char[] password)
Initializes the cipher with the given PBE derived key bytes.

Parameters:
password - PBE password.


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