Package org.apache.fulcrum.jce.crypto
Class CryptoStreamFactoryTemplate
- java.lang.Object
-
- org.apache.fulcrum.jce.crypto.CryptoStreamFactoryTemplate
-
- All Implemented Interfaces:
CryptoStreamFactory
- Direct Known Subclasses:
CryptoStreamFactoryImpl
public abstract class CryptoStreamFactoryTemplate 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
-
-
Field Summary
Fields Modifier and Type Field Description protected static CryptoStreamFactory
instance
the default instance
-
Constructor Summary
Constructors Constructor Description CryptoStreamFactoryTemplate()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Cipher
createCipher(int encryptMode, char[] password)
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()
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.abstract InputStream
getSmartInputStream(InputStream is, char[] password)
Creates a smart decrypting input stream using a given password.static void
setInstance(CryptoStreamFactory instance)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.fulcrum.jce.crypto.CryptoStreamFactory
getAlgorithm
-
-
-
-
Field Detail
-
instance
protected static CryptoStreamFactory instance
the default instance
-
-
Constructor Detail
-
CryptoStreamFactoryTemplate
public CryptoStreamFactoryTemplate()
-
-
Method Detail
-
getInstance
public static CryptoStreamFactory getInstance()
-
setInstance
public static void setInstance(CryptoStreamFactory 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 interfaceCryptoStreamFactory
- Parameters:
is
- the input stream to be wrappeddecryptionMode
- the decryption mode (true|false|auto)- Returns:
- an decrypting input stream
- Throws:
GeneralSecurityException
- creating the input stream failedIOException
- 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 interfaceCryptoStreamFactory
- Parameters:
is
- the input stream to be wrappeddecryptionMode
- the decryption mode (true|false|auto)password
- the password to be used- Returns:
- an decrypting input stream
- Throws:
GeneralSecurityException
- creating the input stream failedIOException
- 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 interfaceCryptoStreamFactory
- Parameters:
is
- the input stream to be wrapped- Returns:
- an decrypting input stream
- Throws:
GeneralSecurityException
- creating the input stream failedIOException
- 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 interfaceCryptoStreamFactory
- Parameters:
is
- the input stream to be wrappedpassword
- the password to be used- Returns:
- an decrypting input stream
- Throws:
GeneralSecurityException
- creating the input stream failedIOException
- 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 interfaceCryptoStreamFactory
- Parameters:
is
- the input stream to be wrapped- Returns:
- an decrypting input stream
- Throws:
GeneralSecurityException
- creating the input stream failedIOException
- creating the input stream failed- See Also:
CryptoStreamFactory.getSmartInputStream(java.io.InputStream)
-
getSmartInputStream
public abstract 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 interfaceCryptoStreamFactory
- Parameters:
is
- the input stream to be wrappedpassword
- the password to be used- Returns:
- an decrypting input stream
- Throws:
GeneralSecurityException
- creating the input stream failedIOException
- 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 interfaceCryptoStreamFactory
- Parameters:
os
- the output stream to be wrapped- Returns:
- an encrypting output stream
- Throws:
GeneralSecurityException
- creating the output stream failedIOException
- creating the output 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 interfaceCryptoStreamFactory
- Parameters:
os
- the output stream to be wrappedpassword
- the password to be used- Returns:
- an encrypting output stream
- Throws:
GeneralSecurityException
- creating the output stream failedIOException
- creating the output stream failed- See Also:
CryptoStreamFactory.getOutputStream(java.io.OutputStream, char[])
-
createCipher
protected abstract Cipher createCipher(int encryptMode, char[] password) throws GeneralSecurityException, IOException
- Throws:
GeneralSecurityException
IOException
-
-