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 java.lang.Object
implements CryptoStreamFactory

Concrete factory for creating encrypting/decrypting streams. The implementation uses the JCE (Java Crypto Extension) either supplied by SUN (using SunJCE 1.42) or an custom provider such as BouncyCastle or the newer Cryptix libraries. The implementation uses as PBEWithMD5AndTripleDES 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, java.lang.String algorithm, java.lang.String providerName)
          Constructor
 
Method Summary
 java.io.InputStream getInputStream(java.io.InputStream is)
          Creates a decrypting input stream.
 java.io.InputStream getInputStream(java.io.InputStream is, char[] password)
          Creates an decrypting input stream
static CryptoStreamFactory getInstance()
          Factory method to get a default instance
 java.io.OutputStream getOutputStream(java.io.OutputStream os, char[] password)
          Creates an encrypting output stream
 java.io.InputStream getSmartInputStream(java.io.InputStream is)
          Creates a smart decrypting input stream.
 java.io.InputStream getSmartInputStream(java.io.InputStream is, char[] password)
          Creates an decrypting input stream
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,
                               java.lang.String algorithm,
                               java.lang.String providerName)
Constructor

Parameters:
salt - the salt for the PBE algorithm
count - the iteration for PBEParameterSpec
algorithm - the algorithm to be used
providerName - the name of the JCE provide to b used
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 java.io.InputStream getInputStream(java.io.InputStream is)
                                   throws java.security.GeneralSecurityException,
                                          java.io.IOException
Description copied from interface: CryptoStreamFactory
Creates a decrypting input stream.

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

getInputStream

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

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:
java.security.GeneralSecurityException - creating the input stream failed
java.io.IOException - creating the input stream failed
See Also:
CryptoStreamFactory.getInputStream(java.io.InputStream,char[])

getSmartInputStream

public java.io.InputStream getSmartInputStream(java.io.InputStream is)
                                        throws java.security.GeneralSecurityException,
                                               java.io.IOException
Description copied from interface: CryptoStreamFactory
Creates a smart decrypting input stream.

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

getSmartInputStream

public java.io.InputStream getSmartInputStream(java.io.InputStream is,
                                               char[] password)
                                        throws java.security.GeneralSecurityException,
                                               java.io.IOException
Description copied from interface: CryptoStreamFactory
Creates an decrypting input stream

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:
java.security.GeneralSecurityException - creating the input stream failed
java.io.IOException - creating the input stream failed
See Also:
CryptoStreamFactory.getSmartInputStream(java.io.InputStream,char[])

getOutputStream

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

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:
java.security.GeneralSecurityException - creating the ouptut stream failed
java.io.IOException - creating the ouptut stream failed
See Also:
CryptoStreamFactory.getOutputStream(java.io.OutputStream, char[])


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