|
|||||||||
| Home >> All >> renderkits >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
renderkits.util
Class ByteArrayGuard

java.lang.Objectrenderkits.util.ByteArrayGuard
- public class ByteArrayGuard
- extends java.lang.Object
This utility class provides services to encrypt or decrypt a byte array. The algorithm used to encrypt byte array is 3DES with CBC The algorithm used to create the message authentication code (MAC) is SHA1
Original author Inderjeet Singh, J2EE Blue Prints Team. Modified to suit JSF needs.
| Field Summary | |
static int |
DEFAULT_IV_LENGTH
|
static int |
DEFAULT_KEY_LENGTH
|
static int |
DEFAULT_MAC_LENGTH
|
static int |
DEFAULT_PASSWORD_LENGTH
|
private int |
ivLength
|
private int |
keyLength
|
private static java.util.logging.Logger |
logger
|
private int |
macLength
|
private java.lang.String |
password
|
private static java.security.SecureRandom |
prng
|
static java.lang.String |
SESSION_KEY_FOR_PASSWORD
|
| Constructor Summary | |
ByteArrayGuard()
|
|
ByteArrayGuard(int keyLength,
int macLength,
int ivLength)
|
|
| Method Summary | |
private static void |
byte2hex(byte b,
java.lang.StringBuffer buf)
Converts a byte to hex digit and writes to the supplied buffer |
private static byte[] |
concatBytes(byte[] array1,
byte[] array2)
This method concatenates two byte arrays |
private byte[] |
convertPasswordToKey(byte[] password)
This method converts the specified password into a key in a deterministic manner. |
private byte[] |
convertPasswordToKey(java.lang.String password)
A convenience alias to the above method which takes a string as the password. |
byte[] |
decrypt(javax.faces.context.FacesContext context,
byte[] securedata)
Decrypts the specified byte array using the specified password, and generates an inputstream from it. |
byte[] |
encrypt(javax.faces.context.FacesContext context,
byte[] plaindata)
Encrypts the specified plaindata using the specified password. |
private static javax.crypto.Cipher |
getBlockCipherForDecryption(byte[] rawKey,
byte[] iv)
|
private javax.crypto.Cipher |
getBlockCipherForEncryption(byte[] rawKey)
|
private static java.lang.String |
getHexString(byte[] b)
|
private javax.crypto.Mac |
getMac(byte[] rawKey)
|
private java.lang.String |
getPasswordToSecureState(javax.faces.context.FacesContext context)
This method provides a password to be used for encryption/decryption of client-side state. |
private static java.security.SecureRandom |
getPRNG()
|
private static int |
getRandomInt()
|
(package private) static java.lang.String |
getRandomString(int size)
Generates a cryptographically random string |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
DEFAULT_KEY_LENGTH
public static final int DEFAULT_KEY_LENGTH
- See Also:
- Constant Field Values
DEFAULT_MAC_LENGTH
public static final int DEFAULT_MAC_LENGTH
- See Also:
- Constant Field Values
DEFAULT_IV_LENGTH
public static final int DEFAULT_IV_LENGTH
- See Also:
- Constant Field Values
SESSION_KEY_FOR_PASSWORD
public static final java.lang.String SESSION_KEY_FOR_PASSWORD
- See Also:
- Constant Field Values
DEFAULT_PASSWORD_LENGTH
public static final int DEFAULT_PASSWORD_LENGTH
- See Also:
- Constant Field Values
logger
private static java.util.logging.Logger logger
keyLength
private int keyLength
macLength
private int macLength
ivLength
private int ivLength
password
private java.lang.String password
prng
private static java.security.SecureRandom prng
| Constructor Detail |
ByteArrayGuard
public ByteArrayGuard()
ByteArrayGuard
public ByteArrayGuard(int keyLength,
int macLength,
int ivLength)
| Method Detail |
encrypt
public byte[] encrypt(javax.faces.context.FacesContext context, byte[] plaindata)
- Encrypts the specified plaindata using the specified password. It also
stores the MAC and the IV in the output. The 20-byte MAC is stored
first, followed by the 8-byte IV, followed by the encrypted
contents of the file.
decrypt
public byte[] decrypt(javax.faces.context.FacesContext context, byte[] securedata)
- Decrypts the specified byte array using the specified password, and
generates an inputstream from it. The file must be encrypted by the
above method for encryption. The method also verifies the MAC. It
uses the IV present in the file for decryption.
getPasswordToSecureState
private java.lang.String getPasswordToSecureState(javax.faces.context.FacesContext context)
- This method provides a password to be used for encryption/decryption of
client-side state.
convertPasswordToKey
private byte[] convertPasswordToKey(byte[] password)
- This method converts the specified password into a key in a
deterministic manner. The key is then usable for creating ciphers
and MACs.
convertPasswordToKey
private byte[] convertPasswordToKey(java.lang.String password)
- A convenience alias to the above method which takes a string as
the password.
getBlockCipherForEncryption
private javax.crypto.Cipher getBlockCipherForEncryption(byte[] rawKey)
getBlockCipherForDecryption
private static javax.crypto.Cipher getBlockCipherForDecryption(byte[] rawKey, byte[] iv)
getMac
private javax.crypto.Mac getMac(byte[] rawKey)
getRandomString
static java.lang.String getRandomString(int size)
- Generates a cryptographically random string
getRandomInt
private static int getRandomInt()
getPRNG
private static java.security.SecureRandom getPRNG()
getHexString
private static java.lang.String getHexString(byte[] b)
concatBytes
private static byte[] concatBytes(byte[] array1,
byte[] array2)
- This method concatenates two byte arrays
byte2hex
private static void byte2hex(byte b,
java.lang.StringBuffer buf)
- Converts a byte to hex digit and writes to the supplied buffer
|
|||||||||
| Home >> All >> renderkits >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
renderkits.util.ByteArrayGuard