Class DefaultEncryption
- All Implemented Interfaces:
Encryption
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDecrypts the given encrypted value.Encrypts the given plain-text value using the configured encryption algorithm and key.static Encryption
fromEncryptionKey
(@NonNull String encryptionKey) static String
Generates a new encryption key using the default encryption mechanism.Returns the name or identifier of the encryption algorithm used.Returns the encryption key used by this implementation.boolean
isEncrypted
(String value) Returnstrue
if the given value is considered encrypted by this implementation.protected boolean
-
Constructor Details
-
DefaultEncryption
public DefaultEncryption()
-
-
Method Details
-
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
-
encrypt
Description copied from interface:Encryption
Encrypts the given plain-text value using the configured encryption algorithm and key.- Specified by:
encrypt
in interfaceEncryption
- Parameters:
value
- the plain-text value to encrypt- Returns:
- the encrypted form of the input value
-
decrypt
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 interfaceEncryption
- Parameters:
value
- the encrypted string to decrypt- Returns:
- the decrypted plain-text value
-
isEncryptedWithKnownAlgorithm
-
isEncrypted
Description copied from interface:Encryption
Returnstrue
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 interfaceEncryption
- Parameters:
value
- the value to check- Returns:
true
if the value appears to be encrypted,false
otherwise
-
getAlgorithm
Description copied from interface:Encryption
Returns the name or identifier of the encryption algorithm used.- Specified by:
getAlgorithm
in interfaceEncryption
- Returns:
- the name of the algorithm (e.g., "AES", "RSA", "noop")
-
getEncryptionKey
Description copied from interface:Encryption
Returns the encryption key used by this implementation.- Specified by:
getEncryptionKey
in interfaceEncryption
- Returns:
- the configured key for encryption/decryption, usually a secret or secret reference
-