Class DefaultEncryption
- All Implemented Interfaces:
Encryption
Encryption interface used in Fluxzero.
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 Fluxzero 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 EncryptionfromEncryptionKey(@NonNull String encryptionKey) static StringGenerates 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.booleanisEncrypted(String value) Returnstrueif 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:EncryptionEncrypts the given plain-text value using the configured encryption algorithm and key.- Specified by:
encryptin interfaceEncryption- Parameters:
value- the plain-text value to encrypt- Returns:
- the encrypted form of the input value
-
decrypt
Description copied from interface:EncryptionDecrypts 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:
decryptin interfaceEncryption- Parameters:
value- the encrypted string to decrypt- Returns:
- the decrypted plain-text value
-
isEncryptedWithKnownAlgorithm
-
isEncrypted
Description copied from interface:EncryptionReturnstrueif the given value is considered encrypted by this implementation.Useful for avoiding double-encryption or determining if decryption is required.
- Specified by:
isEncryptedin interfaceEncryption- Parameters:
value- the value to check- Returns:
trueif the value appears to be encrypted,falseotherwise
-
getAlgorithm
Description copied from interface:EncryptionReturns the name or identifier of the encryption algorithm used.- Specified by:
getAlgorithmin interfaceEncryption- Returns:
- the name of the algorithm (e.g., "AES", "RSA", "noop")
-
getEncryptionKey
Description copied from interface:EncryptionReturns the encryption key used by this implementation.- Specified by:
getEncryptionKeyin interfaceEncryption- Returns:
- the configured key for encryption/decryption, usually a secret or secret reference
-