net.sourceforge.jcetaglib.lib
Class PBECrypt

java.lang.Object
  extended bynet.sourceforge.jcetaglib.lib.PBECrypt

public class PBECrypt
extends java.lang.Object

PBE (Password-based) encryption & decryption routines for use with BouncyCastle JCE provider

Version:
$Id: PBECrypt.java,v 1.3 2004/04/15 07:28:25 hamgert Exp $
Author:
Gert Van Ham, hamgert@users.sourceforge.net, http://jcetaglib.sourceforge.net

Constructor Summary
PBECrypt()
           
 
Method Summary
static void decrypt(java.io.InputStream is, java.io.DataOutputStream daos, java.lang.StringBuffer passphrase, java.lang.String algorithm, int bufferlength)
          Decrypts any inputstream with PBE
static java.lang.StringBuffer decrypt(java.lang.StringBuffer text, java.lang.StringBuffer passphrase, java.lang.String algorithm)
          Decrypts a ciphertext with PBE
static void decryptFile(java.lang.String file, java.lang.String newfile, java.lang.StringBuffer passphrase, java.lang.String algorithm)
          Decrypts a ciphered file with PBE
static void encrypt(java.io.InputStream is, java.io.DataOutputStream daos, byte[] seed, java.lang.StringBuffer passphrase, java.lang.String algorithm, int bufferlength)
          Encrypts any inputstream with PBE (password-based encryption)
static java.lang.StringBuffer encrypt(java.lang.StringBuffer text, java.lang.StringBuffer passphrase, byte[] seed, java.lang.String algorithm)
          Encrypts a string with PBE and returns the ciphered text in BASE64 format.
static java.lang.StringBuffer encrypt(java.lang.StringBuffer text, java.lang.StringBuffer passphrase, java.lang.String algorithm)
          Encrypts a string with PBE and returns the ciphered text in BASE64 format.
static void encryptFile(java.lang.String file, java.lang.String newfile, java.lang.StringBuffer passphrase, byte[] seed, java.lang.String algorithm)
          Encrypts a file with PBE and creates a new file with the result.
static void encryptFile(java.lang.String file, java.lang.String newfile, java.lang.StringBuffer passphrase, java.lang.String algorithm)
          Encrypts a file with PBE and creates a new file with the result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PBECrypt

public PBECrypt()
Method Detail

encrypt

public static java.lang.StringBuffer encrypt(java.lang.StringBuffer text,
                                             java.lang.StringBuffer passphrase,
                                             java.lang.String algorithm)
                                      throws CryptoException
Encrypts a string with PBE and returns the ciphered text in BASE64 format.

Parameters:
text - the text to encrypt
passphrase - password or passphrase
algorithm - encryption algorithm (e.g. "PBEWithSHAAndIDEA-CBC")
Returns:
the cipherstring in BASE64 format
Throws:
CryptoException - for all encryption errors

encrypt

public static java.lang.StringBuffer encrypt(java.lang.StringBuffer text,
                                             java.lang.StringBuffer passphrase,
                                             byte[] seed,
                                             java.lang.String algorithm)
                                      throws CryptoException
Encrypts a string with PBE and returns the ciphered text in BASE64 format.

Parameters:
text - the text to encrypt
passphrase - password or passphrase
seed - the seed for SecureRandom
algorithm - encryption algorithm (e.g. "PBEWithSHAAndIDEA-CBC")
Returns:
the cipherstring in BASE64 format
Throws:
CryptoException - for all encryption errors

encrypt

public static void encrypt(java.io.InputStream is,
                           java.io.DataOutputStream daos,
                           byte[] seed,
                           java.lang.StringBuffer passphrase,
                           java.lang.String algorithm,
                           int bufferlength)
                    throws CryptoException,
                           java.io.IOException
Encrypts any inputstream with PBE (password-based encryption)

Parameters:
is - any inputstream
daos - ciphered outputstream
seed - seed for SecureRandom (optional)
passphrase - the password or passphrase
algorithm - encryption algorithm (e.g. "PBEWithSHAAndIDEA-CBC")
bufferlength - buffer length in bytes
Throws:
CryptoException - for all errors
java.io.IOException

encryptFile

public static void encryptFile(java.lang.String file,
                               java.lang.String newfile,
                               java.lang.StringBuffer passphrase,
                               java.lang.String algorithm)
                        throws CryptoException,
                               java.io.IOException
Encrypts a file with PBE and creates a new file with the result.

Parameters:
file - the file to encrypt
passphrase - password or passphrase
algorithm - encryption algorithm (e.g. "PBEWithSHAAndIDEA-CBC")
Throws:
java.io.IOException - I/O errors
CryptoException - for all encryption errors

encryptFile

public static void encryptFile(java.lang.String file,
                               java.lang.String newfile,
                               java.lang.StringBuffer passphrase,
                               byte[] seed,
                               java.lang.String algorithm)
                        throws CryptoException,
                               java.io.IOException
Encrypts a file with PBE and creates a new file with the result.

Parameters:
file - the file to encrypt
newfile - the encrypted file
passphrase - password or passphrase
seed - the seed for SecureRandom
algorithm - encryption algorithm (e.g. "PBEWithSHAAndIDEA-CBC")
Throws:
java.io.IOException - I/O errors
CryptoException - for all encryption errors

decrypt

public static java.lang.StringBuffer decrypt(java.lang.StringBuffer text,
                                             java.lang.StringBuffer passphrase,
                                             java.lang.String algorithm)
                                      throws CryptoException
Decrypts a ciphertext with PBE

Parameters:
text - the ciphertext
passphrase - password or passphrase
algorithm - encryption algorithm (e.g. "PBEWithSHAAndIDEA-CBC")
Returns:
the decrypted plaintext
Throws:
CryptoException - for all encryption errors

decrypt

public static void decrypt(java.io.InputStream is,
                           java.io.DataOutputStream daos,
                           java.lang.StringBuffer passphrase,
                           java.lang.String algorithm,
                           int bufferlength)
                    throws CryptoException,
                           java.io.IOException
Decrypts any inputstream with PBE

Parameters:
is - the ciphered inputstream
daos - deciphered outputstream
passphrase - password or passphrase
algorithm - encryption algorithm (e.g. "PBEWithSHAAndIDEA-CBC")
bufferlength - buffer length in bytes
Throws:
CryptoException - encryption errors
java.io.IOException - I/O errors

decryptFile

public static void decryptFile(java.lang.String file,
                               java.lang.String newfile,
                               java.lang.StringBuffer passphrase,
                               java.lang.String algorithm)
                        throws CryptoException,
                               java.io.IOException
Decrypts a ciphered file with PBE

Parameters:
file - the file to decrypt
passphrase - the password or passphrase
algorithm - encryption algorithm (e.g. "PBEWithSHAAndIDEA-CBC")
Throws:
CryptoException - for all encryption errors
java.io.IOException - I/O errors