org.apache.fulcrum.jce.crypto
Class CryptoStreamFactoryImpl

java.lang.Object
  extended by org.apache.fulcrum.jce.crypto.CryptoStreamFactoryImpl
All Implemented Interfaces:
CryptoStreamFactory

public final class CryptoStreamFactoryImpl
extends Object
implements CryptoStreamFactory

Concrete factory for creating encrypting/decrypting streams. The implementation uses the JCA (Java Crypto Extension) supplied by SUN (using SunJCE 1.42). The implementation uses as PBEWithMD5AndDES for encryption which should be sufficent for most applications. The implementation also supplies a default password in the case that the programmer don't want to have additional hassles. It is easy to reengineer the password being used but much better than a hard-coded password in the application. The code uses parts from Markus Hahn's Blowfish library found at http://blowfishj.sourceforge.net/

Author:
Siegfried Goeschl , Markus Hahn

Constructor Summary
CryptoStreamFactoryImpl()
          Constructor
CryptoStreamFactoryImpl(byte[] salt, int count)
          Constructor
 
Method Summary
 InputStream getInputStream(InputStream is)
          Creates a decrypting input stream using the default password.
 InputStream getInputStream(InputStream is, char[] password)
          Creates an decrypting input stream using a given password.
 InputStream getInputStream(InputStream is, String decryptionMode)
          Creates input stream based on the decryption mode using the default password.
 InputStream getInputStream(InputStream is, String decryptionMode, char[] password)
          Creates input stream based on the decryption mode using the given password.
static CryptoStreamFactory getInstance()
          Factory method to get a default instance
 OutputStream getOutputStream(OutputStream os)
          Creates an encrypting output stream using the default password.
 OutputStream getOutputStream(OutputStream os, char[] password)
          Creates an encrypting output stream using the given password.
 InputStream getSmartInputStream(InputStream is)
          Creates a smart decrypting input stream using the default password.
 InputStream getSmartInputStream(InputStream is, char[] password)
          Creates a smart decrypting input stream using a given password.
static void setInstance(CryptoStreamFactory instance)
          Set the default instance from an external application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CryptoStreamFactoryImpl

public CryptoStreamFactoryImpl()
Constructor


CryptoStreamFactoryImpl

public CryptoStreamFactoryImpl(byte[] salt,
                               int count)
Constructor

Parameters:
salt - the salt for the PBE algorithm
count - the iteration for PBEParameterSpec
Method Detail

getInstance

public static CryptoStreamFactory getInstance()
Factory method to get a default instance

Returns:
an instance of the CryptoStreamFactory

setInstance

public static void setInstance(CryptoStreamFactory instance)
Set the default instance from an external application.

Parameters:
instance - the new default instance

getInputStream

public InputStream getInputStream(InputStream is,
                                  String decryptionMode)
                           throws GeneralSecurityException,
                                  IOException
Description copied from interface: CryptoStreamFactory
Creates input stream based on the decryption mode using the default password.

Specified by:
getInputStream in interface CryptoStreamFactory
Parameters:
is - the input stream to be wrapped
decryptionMode - the decryption mode (true|false|auto)
Returns:
an decrypting input stream
Throws:
GeneralSecurityException - creating the input stream failed
IOException - creating the input stream failed
See Also:
CryptoStreamFactory.getInputStream(java.io.InputStream, String)

getInputStream

public InputStream getInputStream(InputStream is,
                                  String decryptionMode,
                                  char[] password)
                           throws GeneralSecurityException,
                                  IOException
Description copied from interface: CryptoStreamFactory
Creates input stream based on the decryption mode using the given password.

Specified by:
getInputStream in interface CryptoStreamFactory
Parameters:
is - the input stream to be wrapped
decryptionMode - the decryption mode (true|false|auto)
password - the password to be used
Returns:
an decrypting input stream
Throws:
GeneralSecurityException - creating the input stream failed
IOException - creating the input stream failed
See Also:
CryptoStreamFactory.getInputStream(java.io.InputStream, String, char[])

getInputStream

public InputStream getInputStream(InputStream is)
                           throws GeneralSecurityException,
                                  IOException
Description copied from interface: CryptoStreamFactory
Creates a decrypting input stream using the default password.

Specified by:
getInputStream in interface CryptoStreamFactory
Parameters:
is - the input stream to be wrapped
Returns:
an decrypting input stream
Throws:
GeneralSecurityException - creating the input stream failed
IOException - creating the input stream failed
See Also:
CryptoStreamFactory.getInputStream(java.io.InputStream)

getInputStream

public InputStream getInputStream(InputStream is,
                                  char[] password)
                           throws GeneralSecurityException,
                                  IOException
Description copied from interface: CryptoStreamFactory
Creates an decrypting input stream using a given password.

Specified by:
getInputStream in interface CryptoStreamFactory
Parameters:
is - the input stream to be wrapped
password - the password to be used
Returns:
an decrypting input stream
Throws:
GeneralSecurityException - creating the input stream failed
IOException - creating the input stream failed
See Also:
CryptoStreamFactory.getInputStream(java.io.InputStream,char[])

getSmartInputStream

public InputStream getSmartInputStream(InputStream is)
                                throws GeneralSecurityException,
                                       IOException
Description copied from interface: CryptoStreamFactory
Creates a smart decrypting input stream using the default password. The implementation looks at the binary content to decide if it was encrypted or not thereby providing transparent access to encrypted/unencrypted files.

Specified by:
getSmartInputStream in interface CryptoStreamFactory
Parameters:
is - the input stream to be wrapped
Returns:
an decrypting input stream
Throws:
GeneralSecurityException - creating the input stream failed
IOException - creating the input stream failed
See Also:
CryptoStreamFactory.getSmartInputStream(java.io.InputStream)

getSmartInputStream

public InputStream getSmartInputStream(InputStream is,
                                       char[] password)
                                throws GeneralSecurityException,
                                       IOException
Description copied from interface: CryptoStreamFactory
Creates a smart decrypting input stream using a given password. The implementation looks at the binary content to decide if it was encrypted or not thereby providing transparent access to encrypted/unencrypted files.

Specified by:
getSmartInputStream in interface CryptoStreamFactory
Parameters:
is - the input stream to be wrapped
password - the password to be used
Returns:
an decrypting input stream
Throws:
GeneralSecurityException - creating the input stream failed
IOException - creating the input stream failed
See Also:
CryptoStreamFactory.getSmartInputStream(java.io.InputStream,char[])

getOutputStream

public OutputStream getOutputStream(OutputStream os)
                             throws GeneralSecurityException,
                                    IOException
Description copied from interface: CryptoStreamFactory
Creates an encrypting output stream using the default password.

Specified by:
getOutputStream in interface CryptoStreamFactory
Parameters:
os - the output stream to be wrapped
Returns:
an decrypting input stream
Throws:
GeneralSecurityException - creating the ouptut stream failed
IOException - creating the ouptut stream failed
See Also:
CryptoStreamFactory.getOutputStream(java.io.OutputStream)

getOutputStream

public OutputStream getOutputStream(OutputStream os,
                                    char[] password)
                             throws GeneralSecurityException,
                                    IOException
Description copied from interface: CryptoStreamFactory
Creates an encrypting output stream using the given password.

Specified by:
getOutputStream in interface CryptoStreamFactory
Parameters:
os - the output stream to be wrapped
password - the password to be used
Returns:
an decrypting input stream
Throws:
GeneralSecurityException - creating the ouptut stream failed
IOException - creating the ouptut stream failed
See Also:
CryptoStreamFactory.getOutputStream(java.io.OutputStream, char[])


Copyright © 2008-2009 The Apache Software Foundation. All Rights Reserved.