Class DefaultEncryption

java.lang.Object
io.fluxcapacitor.common.encryption.DefaultEncryption
All Implemented Interfaces:
Encryption

public class DefaultEncryption extends Object implements Encryption
Default implementation of the Encryption interface used in the Flux platform.

This implementation delegates encryption and decryption to an underlying algorithm-specific Encryption strategy (e.g. ChaCha20Poly1305Encryption), while wrapping the result in a recognizable format:


 encrypted|<algorithm>|<ciphertext>
 

This format allows the platform to:

  • Identify encrypted values consistently
  • Support multiple algorithms in the future
  • Perform decryption only when the encryption algorithm matches the delegate

The encryption key is expected to be prefixed with the algorithm, separated by a pipe character. For example:


 ChaCha20|AbcdEfGhIjKlMnOpQrStUvWxYz123456
 

Decryption is only attempted if the algorithm in the encrypted value matches the configured algorithm. If it does not match (e.g. due to a missing or incorrect key), null is returned to indicate that the value cannot be decrypted.

See Also:
  • Constructor Details

    • DefaultEncryption

      public DefaultEncryption()
  • Method Details

    • generateNewEncryptionKey

      public static String generateNewEncryptionKey()
      Generates a new encryption key using the default encryption mechanism. The key is composed of the encryption algorithm identifier and the underlying encryption key, formatted as a concatenated string.
      Returns:
      a string representation of the newly generated encryption key
    • fromEncryptionKey

      public static Encryption fromEncryptionKey(@NonNull @NonNull String encryptionKey)
    • encrypt

      public String encrypt(String value)
      Description copied from interface: Encryption
      Encrypts the given plain-text value using the configured encryption algorithm and key.
      Specified by:
      encrypt in interface Encryption
      Parameters:
      value - the plain-text value to encrypt
      Returns:
      the encrypted form of the input value
    • decrypt

      public String decrypt(String value)
      Description copied from interface: Encryption
      Decrypts the given encrypted value.

      This method assumes that the input is a properly formatted encrypted value produced by the corresponding Encryption.encrypt(String) method.

      Specified by:
      decrypt in interface Encryption
      Parameters:
      value - the encrypted string to decrypt
      Returns:
      the decrypted plain-text value
    • isEncryptedWithKnownAlgorithm

      protected boolean isEncryptedWithKnownAlgorithm(String value)
    • isEncrypted

      public boolean isEncrypted(String value)
      Description copied from interface: Encryption
      Returns true if the given value is considered encrypted by this implementation.

      Useful for avoiding double-encryption or determining if decryption is required.

      Specified by:
      isEncrypted in interface Encryption
      Parameters:
      value - the value to check
      Returns:
      true if the value appears to be encrypted, false otherwise
    • getAlgorithm

      public String getAlgorithm()
      Description copied from interface: Encryption
      Returns the name or identifier of the encryption algorithm used.
      Specified by:
      getAlgorithm in interface Encryption
      Returns:
      the name of the algorithm (e.g., "AES", "RSA", "noop")
    • getEncryptionKey

      public String getEncryptionKey()
      Description copied from interface: Encryption
      Returns the encryption key used by this implementation.
      Specified by:
      getEncryptionKey in interface Encryption
      Returns:
      the configured key for encryption/decryption, usually a secret or secret reference