public class KeyFactory extends Object
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 and Description |
---|
KeyFactory() |
Modifier and Type | Method and Description |
---|---|
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.
|
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 useEncodingException
- 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 useEncodingException
- 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.Copyright © GigaSpaces.