com.force.sdk.oauth.context.store
Class AESUtil

java.lang.Object
  extended by com.force.sdk.oauth.context.store.AESUtil

public final class AESUtil
extends Object

Utility class to handle encryption logic with AES.

Author:
John Simone

Method Summary
static byte[] decrypt(byte[] value, SecretKeySpec skeySpec)
          Decrypts the value using the passed in key.
static byte[] encrypt(byte[] value, SecretKeySpec skeySpec)
          Encrypts the value using the passed in key.
static SecretKeySpec generateRandomKey()
          Generates a random secret key.
static SecretKeySpec getSecretKey()
          Calls getSecretKey(String fileName) with the default filename.
static SecretKeySpec getSecretKey(String fileName)
          Reads in a stored secret key from a properties file and creates a SecretKeySpec object from it.
static SecretKeySpec getSecretKeySpec(String key)
           
static SecretKeySpec recreateSecretKeySpec(String key)
          Creates a SecretKeySpec object from an AES key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encrypt

public static byte[] encrypt(byte[] value,
                             SecretKeySpec skeySpec)
                      throws ForceEncryptionException
Encrypts the value using the passed in key.

Parameters:
value - data to encrypt
skeySpec - encryption key
Returns:
The encrypted data
Throws:
ForceEncryptionException - ForceEncryptionException

decrypt

public static byte[] decrypt(byte[] value,
                             SecretKeySpec skeySpec)
                      throws ForceEncryptionException
Decrypts the value using the passed in key.

Parameters:
value - data to decrypt
skeySpec - The encryption key
Returns:
the decrypted value
Throws:
ForceEncryptionException - ForceEncryptionException

recreateSecretKeySpec

public static SecretKeySpec recreateSecretKeySpec(String key)
                                           throws ForceEncryptionException
Creates a SecretKeySpec object from an AES key. This String could come from a properties file or other means of persistent configuration.

Parameters:
key - String
Returns:
encryption key
Throws:
ForceEncryptionException - ForceEncryptionException

getSecretKey

public static SecretKeySpec getSecretKey()
                                  throws ForceEncryptionException
Calls getSecretKey(String fileName) with the default filename.

Returns:
encryption key
Throws:
ForceEncryptionException - ForceEncryptionException

getSecretKey

public static SecretKeySpec getSecretKey(String fileName)
                                  throws ForceEncryptionException
Reads in a stored secret key from a properties file and creates a SecretKeySpec object from it.

Parameters:
fileName - String
Returns:
encryption key
Throws:
ForceEncryptionException - ForceEncryptionException

getSecretKeySpec

public static SecretKeySpec getSecretKeySpec(String key)
                                      throws ForceEncryptionException
Throws:
ForceEncryptionException

generateRandomKey

public static SecretKeySpec generateRandomKey()
                                       throws ForceEncryptionException
Generates a random secret key.

Returns:
encryption key
Throws:
ForceEncryptionException - ForceEncryptionException


Copyright © 2012. All Rights Reserved.