|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.jaffa.security.EncryptionHelper
This class has some utility functions for encrypting objects using the JCE Security Package. Its main purpose is to be able to take a Object/String and encrypt it, and then convert the encrypted data into a HexString, so that it can be passed arround as a String, and hence used in URL's. A good exmple of this is if you have an Object that you want to pass to a servlet, then you can use this routine to get a HexString version of that object and pass it accross in the URL as a paramater "data=1234567890ABC...", Data will not only be a serialization of the object, it will also be encrypted with a SecretKey, that the recievoing servlet must use when converting it back to an object. The String version of this process is optimized to convert the String in to a UTF-8 byte array. This results in a much smaller string then regular obejct serialization.
| Field Summary | |
static String |
ENCRYPT_POLICY
This is the encryption policy that will be used |
| Constructor Summary | |
EncryptionHelper()
|
|
| Method Summary | |
static SecretKey |
createKey()
This method can be used from the command line for creating a Secret Key. |
static String |
encryptObjectForURL(Object source,
SecretKey key)
Creates an encrypted and encode string from the source object. |
static String |
encryptStringForURL(String source,
SecretKey key)
Creates an encrypted and encode string from the source string. |
static byte |
fromHex(char c)
Utility function to convert a hex character to a number. |
static byte[] |
fromHexString(String in)
Convert a String of hex values into a byte[]. |
static Object |
getObjectFromEncryptedURL(String data,
SecretKey key)
Get an Object from an Encoded and Encrypted String. |
static String |
getStringFromEncryptedURL(String data,
SecretKey key)
Get a String from an Encoded and Encrypted String. |
static byte[] |
intoBytes(String in)
Converts a String (based on an 8-bit character set) into an byte array. |
static byte[] |
intoBytes16(String in)
Converts a String into an byte array. |
static String |
intoHexString(byte[] in)
Converts a byte[] into a hex string representation. |
static String |
intoString(byte[] in)
Converts a byte array into a string. |
static String |
intoString16(byte[] in)
Converts a byte array into a string. |
static void |
main(String[] args)
This method can be used from the command line for creating a Secret Key. |
static SecretKey |
readKey(File file)
Read a file that should contain a serialized Secret key |
static SecretKey |
readKeyClassPath(String name)
Read a file that should contain a serialized Secret key, the file is read as a resource on the classpath |
static char |
toHex(byte b)
Utility function to convert a number into a hex character. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final String ENCRYPT_POLICY
| Constructor Detail |
public EncryptionHelper()
| Method Detail |
public static void main(String[] args)
args - the command line arguments
Requires one mandatory parameter, which is the file name to use to write out the SecretKeypublic static SecretKey createKey()
public static SecretKey readKey(File file)
throws IOException,
ClassNotFoundException
file - The file object that points to the key file
ClassNotFoundException - If the SecretKey class is not available
IOException - If the specfied file can't be loaded
public static SecretKey readKeyClassPath(String name)
throws IOException,
ClassNotFoundException
name - The resource name that points to the key file
ClassNotFoundException - If the SecretKey class is not available
IOException - If the specfied file can't be loaded
public static String encryptStringForURL(String source,
SecretKey key)
throws NoSuchAlgorithmException,
InvalidKeyException,
NoSuchPaddingException,
UnsupportedEncodingException,
IllegalBlockSizeException,
BadPaddingException
source - The source string to encrypt/encodekey - The secret key to use for encryption
NoSuchAlgorithmException - May be thrown by the Cypher module
InvalidKeyException - May be thrown by the Cypher module
NoSuchPaddingException - May be thrown by the Cypher module
UnsupportedEncodingException - May be thrown by the Cypher module
IllegalBlockSizeException - May be thrown by the Cypher module
BadPaddingException - May be thrown by the Cypher module
public static String getStringFromEncryptedURL(String data,
SecretKey key)
throws NoSuchAlgorithmException,
InvalidKeyException,
NoSuchPaddingException,
IllegalBlockSizeException,
BadPaddingException
data - The encoded/encrypted string to processkey - The secret key used needed to decrypt the string
NoSuchAlgorithmException - May be thrown by the Cypher module
InvalidKeyException - May be thrown by the Cypher module
NoSuchPaddingException - May be thrown by the Cypher module
IllegalBlockSizeException - May be thrown by the Cypher module
BadPaddingException - May be thrown by the Cypher module
public static String encryptObjectForURL(Object source,
SecretKey key)
throws NoSuchAlgorithmException,
InvalidKeyException,
NoSuchPaddingException,
UnsupportedEncodingException,
IllegalBlockSizeException,
BadPaddingException,
NotSerializableException
source - The source Object to encrypt/encodekey - The secret key to use for encryption
NoSuchAlgorithmException - May be thrown by the Cypher module
InvalidKeyException - May be thrown by the Cypher module
NoSuchPaddingException - May be thrown by the Cypher module
UnsupportedEncodingException - May be thrown by the Cypher module
IllegalBlockSizeException - May be thrown by the Cypher module
BadPaddingException - May be thrown by the Cypher module
NotSerializableException - if the source object is not Serializable
public static Object getObjectFromEncryptedURL(String data,
SecretKey key)
throws NoSuchAlgorithmException,
InvalidKeyException,
NoSuchPaddingException,
IllegalBlockSizeException,
BadPaddingException
data - The encoded/encrypted string to processkey - The secret key used needed to decrypt the string
NoSuchAlgorithmException - May be thrown by the Cypher module
InvalidKeyException - May be thrown by the Cypher module
NoSuchPaddingException - May be thrown by the Cypher module
IllegalBlockSizeException - May be thrown by the Cypher module
BadPaddingException - May be thrown by the Cypher module
public static byte[] intoBytes(String in)
throws UnsupportedEncodingException
in - The string to be converted
UnsupportedEncodingException - Is thrown if there are any unsupported characters in the string (ie. greater that 8-bits)public static String intoString(byte[] in)
in - byte[] to be converted
public static byte[] intoBytes16(String in)
in - The string to be converted
public static String intoString16(byte[] in)
in - byte[] to be converted
public static String intoHexString(byte[] in)
in - The byte[] to convert
public static byte[] fromHexString(String in)
in - The hex string to be converted
public static char toHex(byte b)
b - The byte to convert
public static byte fromHex(char c)
c - The character to convert
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||