org.apache.fulcrum.jce.crypto
Class CryptoUtil

java.lang.Object
  extended by org.apache.fulcrum.jce.crypto.CryptoUtil

public final class CryptoUtil
extends java.lang.Object

Helper class to provde generic functions to work with CryptoStreams. The code uses parts from Markus Hahn's Blowfish library found at http://blowfishj.sourceforge.net/

Author:
Siegfried Goeschl , Markus Hahn

Constructor Summary
CryptoUtil()
           
 
Method Summary
static void copy(java.io.InputStream is, java.io.OutputStream os)
          Pumps the input stream to the output stream.
static void decrypt(CryptoStreamFactory factory, java.lang.Object source, java.lang.Object target, char[] password)
          Copies from a source to a target object using decryption and a caller-suppier CryptoStreamFactory.
static void decrypt(java.lang.Object source, java.lang.Object target, char[] password)
          Copies from a source to a target object using decryption.
static java.lang.String decryptString(CryptoStreamFactory factory, java.lang.String cipherText, char[] password)
          Decrypts an encrypted string into the plain text.
static java.lang.String decryptString(java.lang.String cipherText, char[] password)
          Decrypts an encrypted string into the plain text.
static void encrypt(CryptoStreamFactory factory, java.lang.Object source, java.lang.Object target, char[] password)
          Copies from a source to a target object using encryption and a caller supplied CryptoStreamFactory.
static void encrypt(java.lang.Object source, java.lang.Object target, char[] password)
          Copies from a source to a target object using encryption
static java.lang.String encryptString(CryptoStreamFactory factory, java.lang.String plainText, char[] password)
          Encrypts a string into a hex string.
static java.lang.String encryptString(java.lang.String plainText, char[] password)
          Encrypts a string into a hex string.
static CryptoStreamFactory getCryptoStreamFactory()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CryptoUtil

public CryptoUtil()
Method Detail

encrypt

public static void encrypt(java.lang.Object source,
                           java.lang.Object target,
                           char[] password)
                    throws java.security.GeneralSecurityException,
                           java.io.IOException
Copies from a source to a target object using encryption

Parameters:
source - the source object
target - the target object
password - the password to use for encryption
Throws:
java.security.GeneralSecurityException - accessing JCE failed
java.io.IOException - accessing the souce failed

encrypt

public static void encrypt(CryptoStreamFactory factory,
                           java.lang.Object source,
                           java.lang.Object target,
                           char[] password)
                    throws java.security.GeneralSecurityException,
                           java.io.IOException
Copies from a source to a target object using encryption and a caller supplied CryptoStreamFactory.

Parameters:
factory - the factory to create the crypto streams
source - the source object
target - the target object
password - the password to use for encryption
Throws:
java.security.GeneralSecurityException - accessing JCE failed
java.io.IOException - accessing the souce failed

decrypt

public static void decrypt(java.lang.Object source,
                           java.lang.Object target,
                           char[] password)
                    throws java.security.GeneralSecurityException,
                           java.io.IOException
Copies from a source to a target object using decryption.

Parameters:
source - the source object
target - the target object
password - the password to use for decryption
Throws:
java.security.GeneralSecurityException - accessing JCE failed
java.io.IOException - accessing the souce failed

decrypt

public static void decrypt(CryptoStreamFactory factory,
                           java.lang.Object source,
                           java.lang.Object target,
                           char[] password)
                    throws java.security.GeneralSecurityException,
                           java.io.IOException
Copies from a source to a target object using decryption and a caller-suppier CryptoStreamFactory.

Parameters:
factory - the factory to create the crypto streams
source - the source object
target - the target object
password - the password to use for decryption
Throws:
java.security.GeneralSecurityException - accessing JCE failed
java.io.IOException - accessing the souce failed

encryptString

public static java.lang.String encryptString(java.lang.String plainText,
                                             char[] password)
                                      throws java.security.GeneralSecurityException,
                                             java.io.IOException
Encrypts a string into a hex string.

Parameters:
plainText - the plain text to be encrypted
password - the password for encryption
Returns:
the encrypted string
Throws:
java.security.GeneralSecurityException - accessing JCE failed
java.io.IOException - accessing the souce failed

encryptString

public static java.lang.String encryptString(CryptoStreamFactory factory,
                                             java.lang.String plainText,
                                             char[] password)
                                      throws java.security.GeneralSecurityException,
                                             java.io.IOException
Encrypts a string into a hex string.

Parameters:
factory - the factory to create the crypto streams
plainText - the plain text to be encrypted
password - the password for encryption
Returns:
the encrypted string
Throws:
java.security.GeneralSecurityException - accessing JCE failed
java.io.IOException - accessing the souce failed

decryptString

public static java.lang.String decryptString(java.lang.String cipherText,
                                             char[] password)
                                      throws java.security.GeneralSecurityException,
                                             java.io.IOException
Decrypts an encrypted string into the plain text. The encrypted string must be a hex string created by encryptString.

Parameters:
cipherText - the encrypted text to be decrypted
password - the password for decryption
Returns:
the decrypted string
Throws:
java.security.GeneralSecurityException - accessing JCE failed
java.io.IOException - accessing the souce failed

decryptString

public static java.lang.String decryptString(CryptoStreamFactory factory,
                                             java.lang.String cipherText,
                                             char[] password)
                                      throws java.security.GeneralSecurityException,
                                             java.io.IOException
Decrypts an encrypted string into the plain text. The encrypted string must be a hex string created by encryptString.

Parameters:
factory - the factory to create the crypto streams
cipherText - the encrypted text to be decrypted
password - the password for decryption
Returns:
the decrypted string
Throws:
java.security.GeneralSecurityException - accessing JCE failed
java.io.IOException - accessing the souce failed

copy

public static void copy(java.io.InputStream is,
                        java.io.OutputStream os)
                 throws java.io.IOException
Pumps the input stream to the output stream.

Parameters:
is - the source input stream
os - the target output stream
Throws:
java.io.IOException - the copying failed

getCryptoStreamFactory

public static CryptoStreamFactory getCryptoStreamFactory()
Returns:
the CryptoStreamFactory to be used


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.