java.lang.Object
com.cryptoalgo.oursql.support.SecretsStore
Manage storage of encrypted and unencrypted secrets
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn exception for various failures during storage/retrieval of secrets -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringRetrieves data stored in plaintext formstatic StringRetrieve encrypted data in plaintext formstatic voidStore text in plaintext form without any encryptionstatic voidStore text encrypted in AES-GCM.static voidStore text encrypted in a user-specified algo.static booleanCheck if a secret is present at the specified storeKey.static booleanisEncrypted(String storeKey) Check if stored data at a particular key is stored in encrypted form.static booleanisEncrypted(String storeKey, boolean def) Convenience method to check if a particular secret is encrypted.static voidDeletes a secret stored at a specified storeKey
-
Constructor Details
-
SecretsStore
public SecretsStore()
-
-
Method Details
-
encrypt
Store text in plaintext form without any encryption- Parameters:
plainText- Plain text to storestoreKey- A key to use for storage in Java Preferences
-
encrypt
public static void encrypt(String plainText, String password, String storeKey) throws SecretsStore.StoreException Store text encrypted in AES-GCM. Callsencrypt(String, String, String, String)with the default algorithm, currentlyAES/GCM/NoPadding- Parameters:
plainText- Plain text to storepassword- Encryption passwordstoreKey- A key to use for storage in Java Preferences- Throws:
SecretsStore.StoreException- If encryption failed- See Also:
-
encrypt
public static void encrypt(String plainText, String password, String algo, String storeKey) throws SecretsStore.StoreException Store text encrypted in a user-specified algo.- Parameters:
plainText- Plain text to storepassword- Encryption passwordalgo- Encryption algorithmstoreKey- A key to use for storage in Java Preferences- Throws:
SecretsStore.StoreException- If encryption failed
-
decrypt
Retrieve encrypted data in plaintext form- Parameters:
password- Encryption passwordstoreKey- Preferences key to retrieve secret from- Returns:
- Decrypted secret
- Throws:
SecretsStore.StoreException- If decryption failed for whatever reason (e.g. wrong password)
-
decrypt
Retrieves data stored in plaintext form- Parameters:
storeKey- Preferences key to retrieve secret from- Returns:
- Retrieved secret
- Throws:
SecretsStore.StoreException- If decryption failed for whatever reason (e.g. the secret is encrypted)
-
isEncrypted
Check if stored data at a particular key is stored in encrypted form. Does extensive sanity checking to ensure all required keys are present.- Parameters:
storeKey- Key of secret to check encryption status of- Returns:
- True if data is stored in encrypted form, false if it's stored in plaintext
- Throws:
SecretsStore.StoreException- If the secret could not be retrieved or expected values were missing
-
isEncrypted
Convenience method to check if a particular secret is encrypted. Catches exceptions and returns a default value instead.- Parameters:
storeKey- Key of secret to check encryption status ofdef- Value to return if an exception occurred while checking if the secret is encrypted- Returns:
- True if the secret at
storeKeyis encrypted, - See Also:
-
remove
Deletes a secret stored at a specified storeKey- Parameters:
storeKey- Key of secret to delete- Throws:
BackingStoreException- If the underlying Preferences storage driver threw an exception
-
exists
Check if a secret is present at the specified storeKey. Only checks for the existence, not the validity, of a secret.- Parameters:
storeKey- key to check- Returns:
- True if data is present at the specified storeKey
-