Package com.gigaspaces.security.encoding
Class KeyFactory
java.lang.Object
com.gigaspaces.security.encoding.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());
- Since:
- 7.0.1
- Author:
- Moran Avigdor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SecretKeygenerateKey(byte[] key, String algorithm) Generate a key based on a secret key from the given byte array.static SecretKeygenerateKey(String algorithm) Generate a 128 bit key using the key generator of the algorithm provided.static SecretKeygenerateKey(String key, String algorithm) Generate a key based on the provided secret.static SecretKeyLoads theSecretKeyfile from a resource located in the classpath or jar.static voidStores the secret key to the provided file.
-
Constructor Details
-
KeyFactory
public KeyFactory()
-
-
Method Details
-
generateKey
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
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
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
Loads theSecretKeyfile 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
Stores the secret key to the provided file.- Parameters:
key- a secret key.file- a file to write to.
-