Project Wonder 5.0

er.extensions.crypting
Class ERXCrypto

java.lang.Object
  extended by er.extensions.crypting.ERXCrypto

public class ERXCrypto
extends java.lang.Object

Provides a wrapper around common encryption and decryption operations. ERXCrypto provides built-in support for DES and Blowfish crypters. You can use the "er.extensions.ERXCrypto.crypters" property to override or provide your own. If you only want DES and/or Blowfish, you don't need to set crypters yourself.

Author:
?
Properties
er.extensions.ERXCrypto.default the name of the default crypter algorithm (default = "Blowfish")
           
er.extensions.ERXCrypto.crypters comma-separated list of crypter algorithms (i.e. "DES,Blowfish")
           
er.extensions.ERXCrypto.crypter.[Algorithm] crypter class name, should be one for each algorithm in crypters list (i.e. er.extensions.ERXCrypto.crypter.DES)
           

Field Summary
static java.lang.String AES
          The constant for the AES encryption algorithm.
static java.lang.String BLOWFISH
          The constant for the Blowfish encryption algorithm.
static java.lang.String DES
          The constant for the DES encryption algorithm.
static org.apache.log4j.Logger log
          logging support
 
Constructor Summary
ERXCrypto()
           
 
Method Summary
static byte[] base64Decode(java.lang.String s)
          Base64 decodes the passed in String
static java.lang.String base64Encode(byte[] byteArray)
          Base64 encodes the passed in byte[]
static java.lang.String base64EncryptedString(java.lang.String clearText)
          Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)
static java.lang.String base64EncryptedString(java.lang.String clearText, java.security.Key secretKey)
          Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)
static java.lang.String base64HashedString(java.lang.String v)
          Uses the SHA hash algorithm found in the Sun JCE to hash the passed in String.
static byte[] base64urlDecode(java.lang.String s)
          Base64url decodes the passed in String
static java.lang.String base64urlEncode(byte[] byteArray)
          Base64url encodes the passed in byte[]
static java.lang.String blowfishDecode(java.lang.String encryptedText)
          Deprecated. use ERXBlowfishCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.BLOWFISH)
static java.lang.String blowfishEncode(java.lang.String clearText)
          Deprecated. use ERXBlowfishCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.BLOWFISH)
static java.lang.String bytesToString(byte[] bytes)
          Deprecated. use ERXStringUtilities.byteArrayToHexString instead.
static ERXCrypterInterface crypterForAlgorithm(java.lang.String algorithm)
          Returns the crypter for the given algorithm.
static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.String> decodedFormValuesDictionary(com.webobjects.foundation.NSDictionary<java.lang.String,com.webobjects.foundation.NSArray<java.lang.String>> dict)
          Decodes all of the values from a given dictionary using the default crypter.
static java.lang.String decryptedBase64String(java.lang.String encryptedText)
          Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)
static java.lang.String decryptedBase64String(java.lang.String encryptedText, java.security.Key secretKey)
          Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)
static ERXCrypterInterface defaultCrypter()
          Returns the default crypter.
static void main(java.lang.String[] args)
          Run this with ERXMainRunner passing in the plaintext you want to encrypt using the default crypter.
static void setCrypterForAlgorithm(ERXCrypterInterface crypter, java.lang.String algorithm)
          Sets the crypter for the given algorithm.
static void setSecretKeyPath(java.lang.String secretKeyPath)
          Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)
static void setSecretKeyPathFramework(java.lang.String secretKeyPathFramework)
          Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)
static java.lang.String shaEncode(java.lang.String text)
          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 org.apache.log4j.Logger log
logging support


DES

public static final java.lang.String DES
The constant for the DES encryption algorithm.

See Also:
Constant Field Values

BLOWFISH

public static final java.lang.String BLOWFISH
The constant for the Blowfish encryption algorithm.

See Also:
Constant Field Values

AES

public static final java.lang.String AES
The constant for the AES encryption algorithm.

See Also:
Constant Field Values
Constructor Detail

ERXCrypto

public ERXCrypto()
Method Detail

defaultCrypter

public static ERXCrypterInterface defaultCrypter()
Returns the default crypter. By default this is Blowfish, but you can override the choice by setting er.extensions.ERXCrypto.default.

Returns:
the default crypter

setCrypterForAlgorithm

public static void setCrypterForAlgorithm(ERXCrypterInterface crypter,
                                          java.lang.String algorithm)
Sets the crypter for the given algorithm.

Parameters:
crypter - the crypter to use
algorithm - the algorithm name

crypterForAlgorithm

public static ERXCrypterInterface crypterForAlgorithm(java.lang.String algorithm)
Returns the crypter for the given algorithm. By default, DES and Blowfish are available ("DES", "Blowfish", etc).

Parameters:
algorithm - the algorithm to lookup
Returns:
the corresponding crypter
Throws:
java.lang.IllegalArgumentException - if there is no crypter for the given algorithm

decodedFormValuesDictionary

public static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.String> decodedFormValuesDictionary(com.webobjects.foundation.NSDictionary<java.lang.String,com.webobjects.foundation.NSArray<java.lang.String>> dict)
Decodes all of the values from a given dictionary using the default crypter.

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

base64HashedString

public static java.lang.String base64HashedString(java.lang.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.


shaEncode

public static java.lang.String shaEncode(java.lang.String text)
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:
text - to be put through the sha digest
Returns:
hashed form of the given string

base64Encode

public static java.lang.String base64Encode(byte[] byteArray)
Base64 encodes the passed in byte[]


base64urlEncode

public static java.lang.String base64urlEncode(byte[] byteArray)
Base64url encodes the passed in byte[]


base64Decode

public static byte[] base64Decode(java.lang.String s)
                           throws java.io.IOException
Base64 decodes the passed in String

Throws:
java.io.IOException

base64urlDecode

public static byte[] base64urlDecode(java.lang.String s)
                              throws java.io.IOException
Base64url decodes the passed in String

Throws:
java.io.IOException

bytesToString

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


base64EncryptedString

@Deprecated
public static java.lang.String base64EncryptedString(java.lang.String clearText)
Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)


base64EncryptedString

@Deprecated
public static java.lang.String base64EncryptedString(java.lang.String clearText,
                                                                java.security.Key secretKey)
Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)


decryptedBase64String

@Deprecated
public static java.lang.String decryptedBase64String(java.lang.String encryptedText)
Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)


decryptedBase64String

@Deprecated
public static java.lang.String decryptedBase64String(java.lang.String encryptedText,
                                                                java.security.Key secretKey)
Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)


blowfishEncode

@Deprecated
public static java.lang.String blowfishEncode(java.lang.String clearText)
Deprecated. use ERXBlowfishCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.BLOWFISH)


blowfishDecode

@Deprecated
public static java.lang.String blowfishDecode(java.lang.String encryptedText)
Deprecated. use ERXBlowfishCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.BLOWFISH)


setSecretKeyPathFramework

@Deprecated
public static void setSecretKeyPathFramework(java.lang.String secretKeyPathFramework)
Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)


setSecretKeyPath

@Deprecated
public static void setSecretKeyPath(java.lang.String secretKeyPath)
Deprecated. use ERXDESCrypter and/or ERXCrypto.crypterForAlgorithm(ERXCrypto.DES)


main

public static void main(java.lang.String[] args)
Run this with ERXMainRunner passing in the plaintext you want to encrypt using the default crypter. This is useful if you are using encrypted properties and you need a quick way to know what to set the property value to.

Parameters:
args - the plaintext to encrypt

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

Copyright © 2002 – 2007 Project Wonder.