GigaSpaces XAP 9.7.2 API

com.gigaspaces.security.encoding
Class KeyFactory

java.lang.Object
  extended by com.gigaspaces.security.encoding.KeyFactory

public class KeyFactory
extends Object

A convenient factory for handling secret keys.

Keys can be randomly generated using generateKey(String) or using one of the other generate key methods and supplying a key. The SecretKey can then be stored as a resource using storeKey(SecretKey, File), and loaded using the loadKey(String).

 Example usage: Generate a key and store it into a file.
 
  SecretKey key = KeyFactory.generateKey("AES");
  File file = new File("my-secret.key");
  AesKeyFactory.storeKey(key, file);
  ...
  AesKeyFactory.loadKey(file.getAbsolutePath());
 

Since:
7.0.1
Author:
Moran Avigdor

Constructor Summary
KeyFactory()
           
 
Method Summary
static SecretKey generateKey(byte[] key, String algorithm)
          Generate a key based on a secret key from the given byte array.
static SecretKey generateKey(String algorithm)
          Generate a 128 bit key using the key generator of the algorithm provided.
static SecretKey generateKey(String key, String algorithm)
          Generate a key based on the provided secret.
static SecretKey loadKey(String resourceName)
          Loads the SecretKey file from a resource located in the classpath or jar.
static void storeKey(SecretKey key, File file)
          Stores the secret key to the provided file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyFactory

public KeyFactory()
Method Detail

generateKey

public static SecretKey generateKey(String algorithm)
                             throws EncodingException
Generate a 128 bit key using the key generator of the algorithm provided.

Parameters:
algorithm - algorithm to use.
Returns:
a secret key.
Throws:
EncodingException - If any exception occurred while generating a key.

generateKey

public static SecretKey generateKey(String key,
                                    String algorithm)
                             throws EncodingException
Generate a key based on the provided secret.

Parameters:
key - a string to convert using UTF-8 (at least 8 bytes).
algorithm - algorithm to use
Returns:
a secret key
Throws:
EncodingException - If any exception occurred while generating a key.

generateKey

public static SecretKey generateKey(byte[] key,
                                    String algorithm)
                             throws EncodingException
Generate a key based on a secret key from the given byte array.

Parameters:
key - a key to use (at least 8 bytes).
algorithm - algorithm to use
Returns:
a secret key
Throws:
EncodingException - If any exception occurred while generating a key.

loadKey

public static SecretKey loadKey(String resourceName)
Loads the SecretKey file from a resource located in the classpath or jar.

Parameters:
resourceName - The full resource name. Can't be null.
Returns:
the secret key stored in the specified resource.

storeKey

public static void storeKey(SecretKey key,
                            File file)
Stores the secret key to the provided file.

Parameters:
key - a secret key.
file - a file to write to.

GigaSpaces XAP 9.7.2 API

Copyright © GigaSpaces.