Top Description Fields Constructors Methods
com.sun.faces.renderkit

public final Class ByteArrayGuard

extends Object
Class Inheritance
Imports
java.security.InvalidAlgorithmParameterException, .InvalidKeyException, .NoSuchAlgorithmException, .SecureRandom, java.util.Base64, java.util.logging.Level, .Logger, javax.crypto.BadPaddingException, .Cipher, .IllegalBlockSizeException, .KeyGenerator, .Mac, .NoSuchPaddingException, .SecretKey, javax.crypto.spec.IvParameterSpec, .SecretKeySpec, javax.naming.InitialContext, .NamingException, com.sun.faces.RIConstants, com.sun.faces.util.FacesLogger, jakarta.faces.FacesException, jakarta.faces.context.FacesContext, jakarta.servlet.http.HttpSession

This utility class is to provide both encryption and decryption Ciphers to ResponseStateManager implementations wishing to provide encryption support.

The algorithm used to encrypt byte array is AES with CBC.

Original author Inderjeet Singh, J2EE Blue Prints Team. Modified to suit Faces needs.

Field Summary

Modifier and TypeField and Description
private static final String
private static final int
private static final String
private static final int
private static final Logger
private static final String
private static final int
private SecretKey
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private boolean
areArrayEqualsConstantTime(byte[] array1, byte[] array2)

private static byte[]

Returns:

a byte array of array1||array2
concatBytes
(byte[]
first byte array to be concatenated
array1
,
byte[]
second byte array to be concatenated
array2
)

This method concatenates two byte arrays

public byte[]

Returns:

Decrypted byte array.
decrypt
(FacesContext facesContext, byte[]
Encrypted byte array to be decrypted.
bytes
)

This method decrypts the provided byte array.

public byte[]

Returns:

the encrypted byte array.
encrypt
(FacesContext facesContext, byte[]
The byte array to be encrypted.
bytes
)

This method: Encrypts bytes using a cipher.

private SecretKey
getSecretKey(FacesContext facesContext)

private void
setupKeyAndMac()

Generates secret key.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CIPHER_CODEback to summary
private static final String CIPHER_CODE
IV_LENGTHback to summary
private static final int IV_LENGTH
KEY_ALGORITHMback to summary
private static final String KEY_ALGORITHM
KEY_LENGTHback to summary
private static final int KEY_LENGTH
LOGGERback to summary
private static final Logger LOGGER
MAC_CODEback to summary
private static final String MAC_CODE
MAC_LENGTHback to summary
private static final int MAC_LENGTH
skback to summary
private SecretKey sk
SK_SESSION_KEYback to summary
private static final String SK_SESSION_KEY

Constructor Detail

ByteArrayGuardback to summary
public ByteArrayGuard()

Method Detail

areArrayEqualsConstantTimeback to summary
private boolean areArrayEqualsConstantTime(byte[] array1, byte[] array2)
concatBytesback to summary
private static byte[] concatBytes(byte[] array1, byte[] array2)

This method concatenates two byte arrays

Parameters
array1:byte[]

first byte array to be concatenated

array2:byte[]

second byte array to be concatenated

Returns:byte[]

a byte array of array1||array2

decryptback to summary
public byte[] decrypt(FacesContext facesContext, byte[] bytes)

This method decrypts the provided byte array. The decryption is only performed if the regenerated MAC is the same as the MAC for the received value.

Parameters
bytes:byte[]

Encrypted byte array to be decrypted.

Returns:byte[]

Decrypted byte array.

encryptback to summary
public byte[] encrypt(FacesContext facesContext, byte[] bytes)

This method: Encrypts bytes using a cipher. Generates MAC for intialization vector of the cipher Generates MAC for encrypted data Returns a byte array consisting of the following concatenated together: |MAC for cnrypted Data | MAC for Init Vector | Encrypted Data |

Parameters
bytes:byte[]

The byte array to be encrypted.

Returns:byte[]

the encrypted byte array.

getSecretKeyback to summary
private SecretKey getSecretKey(FacesContext facesContext)
setupKeyAndMacback to summary
private void setupKeyAndMac()

Generates secret key. Initializes MAC(s).