Project Wonder 2.0

er.extensions
Class ERXCrypto

java.lang.Object
  extended byer.extensions.ERXCrypto

public class ERXCrypto
extends Object

Provides a nice wrapper around the blowfish cipher and the sha digest algorithms.

The blowfish cipher is a two-way cipher meaning the original string that was encrypted can be retrieved. The blowfish cipher uses a secret key that should be set in the System properties using the key: ERBlowfishCipherKey. The way that this version of the blowfish cipher is enrcypted it is safe to use as a form value.

The sha digest uses one-way encryption to form a hash of a given string. The digest formed is safe for use in form values and cookies.


Field Summary
static int BLOCK_SIZE
          Block size of blowfish encrypted strings
static ERXLogger log
          logging support
 
Constructor Summary
ERXCrypto()
           
 
Method Summary
static String base64EncryptedString(String v)
          DES Encrypts and then base64 encodes the passed in String using the secret key returned by secretKey.
static String base64EncryptedString(String v, Key sKey)
          DES Encrypts and then base64 encodes the passed in String using the passed in secret key.
static String base64HashedString(String v)
          Uses the SHA hash algorithm found in the Sun JCE to hash the passed in String.
static String blowfishDecode(String s)
          Decodes a blowfish encoded string.
static String blowfishEncode(String s)
          Blowfish encodes a given string using the secret key specified in the System property: ERBlowfishCipherKey.
static String bytesToString(byte[] bytes)
          Deprecated. use ERXStringUtilities.byteArrayToHexString instead.
static NSMutableDictionary decodedFormValuesDictionary(NSDictionary dict)
          Decodes all of the values from a given dictionary using blowfish.
static String decryptedBase64String(String v)
          Base64 decodes and then DES decrypts the passed in string using the secret key returned by secretKey.
static String decryptedBase64String(String v, Key sKey)
          Base64 decodes and then DES decrypts the passed in string using the passed in secret key.
static Key secretKey(File skFile)
           
static File secretKeyFile()
          Returns the File object holding the secret key used by this class's DES encryption routines.
static String secretKeyPath()
           
static String secretKeyPathFramework()
           
static void setSecretKeyPath(String v)
           
static void setSecretKeyPathFramework(String v)
           
static String shaEncode(String string)
          Sha encodes a given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final ERXLogger log
logging support


BLOCK_SIZE

public static final int BLOCK_SIZE
Block size of blowfish encrypted strings

See Also:
Constant Field Values
Constructor Detail

ERXCrypto

public ERXCrypto()
Method Detail

bytesToString

public static String bytesToString(byte[] bytes)
Deprecated. use ERXStringUtilities.byteArrayToHexString instead.


shaEncode

public static String shaEncode(String string)
Sha encodes a given string. The resulting string is safe to use in urls and cookies. From the digest of the string it is nearly impossible to determine what the original string was. Running the same string through the Sha digest multiple times will always produce the same hash.

Parameters:
string - to be put through the sha digest
Returns:
hashed form of the given string

blowfishEncode

public static String blowfishEncode(String s)
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.

Parameters:
s - string to be encrypted
Returns:
encrypted string

blowfishDecode

public static String blowfishDecode(String s)
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.

Parameters:
s - blowfish encoded string to be decoded
Returns:
decode clear text string

decodedFormValuesDictionary

public static NSMutableDictionary decodedFormValuesDictionary(NSDictionary dict)
Decodes all of the values from a given dictionary using blowfish.

Parameters:
dict - dictionary of key value pairs where the values are blowfish encoded strings
Returns:
a dictionary of decoded key-value pairs

secretKeyPathFramework

public static String secretKeyPathFramework()

setSecretKeyPathFramework

public static void setSecretKeyPathFramework(String v)

secretKeyPath

public static String secretKeyPath()

setSecretKeyPath

public static void setSecretKeyPath(String v)

base64HashedString

public static String base64HashedString(String v)
Uses the SHA hash algorithm found in the Sun JCE to hash the passed in String. This String is then base64 encoded and returned.


secretKeyFile

public static File secretKeyFile()
Returns the File object holding the secret key used by this class's DES encryption routines. The secret key is located in a file called "SecretKey.ser"


secretKey

public static Key secretKey(File skFile)

base64EncryptedString

public static String base64EncryptedString(String v)
DES Encrypts and then base64 encodes the passed in String using the secret key returned by secretKey. The base64 encoding is performed to ensure that the encrypted string can be stored in places that don't support extended character sets.


base64EncryptedString

public static String base64EncryptedString(String v,
                                           Key sKey)
DES Encrypts and then base64 encodes the passed in String using the passed in secret key. The base64 encoding is performed to ensure that the encrypted string can be stored in places that don't support extended character sets.


decryptedBase64String

public static String decryptedBase64String(String v)
Base64 decodes and then DES decrypts the passed in string using the secret key returned by secretKey.


decryptedBase64String

public static String decryptedBase64String(String v,
                                           Key sKey)
Base64 decodes and then DES decrypts the passed in string using the passed in secret key.


Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.