JSecurity

org.jsecurity.crypto
Class BlowfishCipher

java.lang.Object
  extended by org.jsecurity.crypto.BlowfishCipher
All Implemented Interfaces:
Cipher

public class BlowfishCipher
extends Object
implements Cipher

JSecurity's default symmetric block Cipher using the Blowfish algorithm. As it is a symmetric Cipher, it uses the same Key to both encrypt and decrypt data. If one is not provided via the setKey method, a default one will be used, BUT NOTE:

Because JSecurity is an open-source project, if anyone knew that you were using JSecurity's default Key, they could download/view the source, and with enough effort, reconstruct the Key and decode encrypted data at will.

JSecurity only really uses Ciphers to encrypt user ids and session ids, so if that information is not critical to you and you think the default key still makes things 'sufficiently difficult', then you can ignore this issue.

However, if you do feel this constitutes sensitive information, it is recommended that you provide your own Key via the setKey method to a Key known only to your application, guaranteeing that no third party can decrypt your data. If you want to know how to do this, you can browse this class's source code for the generateNewKey() method to see how we created our default. Then you can duplicate the same in your environment and set the result on an instance of this class via the setKey method.

Since:
0.9
Author:
Les Hazlewood, Jeremy Haile

Constructor Summary
BlowfishCipher()
           
 
Method Summary
protected  byte[] crypt(byte[] bytes, int mode, byte[] key)
           
protected  byte[] crypt(Cipher cipher, byte[] bytes)
           
 byte[] decrypt(byte[] encrypted, byte[] key)
          Decrypts encrypted data via the specified Cipher key and returns the original (pre-encrypted) data.
 byte[] encrypt(byte[] raw, byte[] key)
          Encrypts data via the specified Cipher key.
static Key generateNewKey()
           
static Key generateNewKey(int keyBitSize)
           
 Key getKey()
           
protected  void init(Cipher cipher, int mode, Key key)
           
static void main(String[] unused)
           
protected  Cipher newCipherInstance()
           
 void setKey(Key key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlowfishCipher

public BlowfishCipher()
Method Detail

getKey

public Key getKey()

setKey

public void setKey(Key key)

encrypt

public byte[] encrypt(byte[] raw,
                      byte[] key)
Description copied from interface: Cipher
Encrypts data via the specified Cipher key. Note that the key must be in a format understood by the Cipher implementation.

Specified by:
encrypt in interface Cipher
Parameters:
raw - the data to encrypt
key - the Cipher key used during encryption.
Returns:
an encrypted representation of the specified raw data.

decrypt

public byte[] decrypt(byte[] encrypted,
                      byte[] key)
Description copied from interface: Cipher
Decrypts encrypted data via the specified Cipher key and returns the original (pre-encrypted) data. Note that the key must be in a format understood by the Cipher implementation.

Specified by:
decrypt in interface Cipher
Parameters:
encrypted - the previously encrypted data to decrypt
key - the Cipher key used during decryption.
Returns:
the original form of the specified encrypted data.

newCipherInstance

protected Cipher newCipherInstance()

init

protected void init(Cipher cipher,
                    int mode,
                    Key key)

crypt

protected byte[] crypt(Cipher cipher,
                       byte[] bytes)

crypt

protected byte[] crypt(byte[] bytes,
                       int mode,
                       byte[] key)

generateNewKey

public static Key generateNewKey()

generateNewKey

public static Key generateNewKey(int keyBitSize)

main

public static void main(String[] unused)
                 throws Exception
Throws:
Exception

JSecurity

Copyright © 2004-2008 JSecurity.