|
GigaSpaces XAP 7.0 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.gigaspaces.security.encoding.KeyFactory
public class KeyFactory
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());
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 |
---|
public KeyFactory()
Method Detail |
---|
public static SecretKey generateKey(String algorithm) throws EncodingException
algorithm
- algorithm to use.
EncodingException
- If any exception occurred while generating a key.public static SecretKey generateKey(String key, String algorithm) throws EncodingException
key
- a string to convert using UTF-8 (at least 8 bytes).algorithm
- algorithm to use
EncodingException
- If any exception occurred while generating a key.public static SecretKey generateKey(byte[] key, String algorithm) throws EncodingException
key
- a key to use (at least 8 bytes).algorithm
- algorithm to use
EncodingException
- If any exception occurred while generating a key.public static SecretKey loadKey(String resourceName)
SecretKey
file from a resource located in the classpath or jar.
resourceName
- The full resource name. Can't be null.
public static void storeKey(SecretKey key, File file)
key
- a secret key.file
- a file to write to.
|
GigaSpaces XAP 7.0 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |