Class SecretsStore

java.lang.Object
com.cryptoalgo.oursql.support.SecretsStore

public class SecretsStore extends Object
Manage storage of encrypted and unencrypted secrets
  • Constructor Details

    • SecretsStore

      public SecretsStore()
  • Method Details

    • encrypt

      public static void encrypt(String plainText, String storeKey)
      Store text in plaintext form without any encryption
      Parameters:
      plainText - Plain text to store
      storeKey - 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. Calls encrypt(String, String, String, String) with the default algorithm, currently AES/GCM/NoPadding
      Parameters:
      plainText - Plain text to store
      password - Encryption password
      storeKey - 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 store
      password - Encryption password
      algo - Encryption algorithm
      storeKey - A key to use for storage in Java Preferences
      Throws:
      SecretsStore.StoreException - If encryption failed
    • decrypt

      public static String decrypt(String password, String storeKey) throws SecretsStore.StoreException
      Retrieve encrypted data in plaintext form
      Parameters:
      password - Encryption password
      storeKey - Preferences key to retrieve secret from
      Returns:
      Decrypted secret
      Throws:
      SecretsStore.StoreException - If decryption failed for whatever reason (e.g. wrong password)
    • decrypt

      public static String decrypt(String storeKey) throws SecretsStore.StoreException
      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

      public static boolean isEncrypted(String storeKey) throws SecretsStore.StoreException
      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

      public static boolean isEncrypted(String storeKey, boolean def)
      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 of
      def - Value to return if an exception occurred while checking if the secret is encrypted
      Returns:
      True if the secret at storeKey is encrypted,
      See Also:
    • remove

      public static void remove(String storeKey) throws BackingStoreException
      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

      public static boolean exists(String storeKey)
      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