Project Wonder 5.0

er.extensions.crypting
Class ERXAbstractBlowfishCrypter

java.lang.Object
  extended by er.extensions.crypting.ERXAbstractBlowfishCrypter
All Implemented Interfaces:
ERXCrypterInterface
Direct Known Subclasses:
ERXBlowfishCrypter, ERXKeyStoreBlowfishCrypter

public abstract class ERXAbstractBlowfishCrypter
extends java.lang.Object
implements ERXCrypterInterface

ERXAbstractBlowfishCrypter is a blowfish implementation of the crypter interface that allows subclasses to override the source of the blowfish key. The blowfish cipher is a two-way cipher meaning the original string that was encrypted can be retrieved. The way that this version of the blowfish cipher is encrypted it is safe to use as a form value.

Author:
mschrag

Field Summary
static org.apache.log4j.Logger log
           
 
Constructor Summary
ERXAbstractBlowfishCrypter()
           
 
Method Summary
 int blockSize()
          Returns the block size for this cipher.
protected  javax.crypto.Cipher createBlowfishCipher(int mode)
          Creates a blowfish cipher for a given mode.
 java.lang.String decrypt(java.lang.String cryptedText)
          Decodes a blowfish encoded string.
protected  javax.crypto.Cipher decryptCipher()
          Method used to return the shared instance of the blowfish decryption cipher.
 java.lang.String encrypt(java.lang.String clearText)
          Blowfish encodes a given string using the secret key specified in the System property: ERBlowfishCipherKey.
protected  javax.crypto.Cipher encryptCipher()
          Method used to return the shared instance of the blowfish encryption cipher.
protected abstract  java.security.Key secretBlowfishKey()
          Returns the secret key to use for this cipher.
 void setBlockSize(int blockSize)
          Sets the block size to use for this cipher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.log4j.Logger log
Constructor Detail

ERXAbstractBlowfishCrypter

public ERXAbstractBlowfishCrypter()
Method Detail

setBlockSize

public void setBlockSize(int blockSize)
Sets the block size to use for this cipher.

Parameters:
blockSize - the block size to use for this cipher

blockSize

public int blockSize()
Returns the block size for this cipher.

Returns:
the block size for this cipher

secretBlowfishKey

protected abstract java.security.Key secretBlowfishKey()
                                                throws java.lang.Exception
Returns the secret key to use for this cipher.

Returns:
a secret key for the blowfish cipher
Throws:
java.lang.Exception

createBlowfishCipher

protected javax.crypto.Cipher createBlowfishCipher(int mode)
Creates a blowfish cipher for a given mode. The two possible modes for a blowfish cipher are: ENCRYPT and DECRYPT.

Parameters:
mode - of the cipher (encrypting or decrypting)
Returns:
a blowfish cipher initialized with the given mode and with the secretKey from the above method.

encryptCipher

protected javax.crypto.Cipher encryptCipher()
Method used to return the shared instance of the blowfish encryption cipher.

Returns:
blowfish encryption cipher

decryptCipher

protected javax.crypto.Cipher decryptCipher()
Method used to return the shared instance of the blowfish decryption cipher.

Returns:
blowfish decryption cipher

decrypt

public java.lang.String decrypt(java.lang.String cryptedText)
Decodes a blowfish encoded string. Note that the originally encoded string should have been encoded with the same secret key as is used for the decoding cipher or else you are going to get garbage. To encode a string have a look at blowfishEncode.

Specified by:
decrypt in interface ERXCrypterInterface
Parameters:
cryptedText - blowfish encoded string to be decoded
Returns:
decode clear text string

encrypt

public java.lang.String encrypt(java.lang.String clearText)
Blowfish encodes a given string using the secret key specified in the System property: ERBlowfishCipherKey. The blowfish cipher is a two way cipher meaning that given the secret key you can de-cipher what the original string is. For one-way encryption look at methods dealing with the Sha alogrithm. To decode a blowfish encoded string use the method: blowfishDecode. The resultant string from encoding a string is safe for use in urls and cookies.

Specified by:
encrypt in interface ERXCrypterInterface
Parameters:
clearText - string to be encrypted
Returns:
encrypted string

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.