PHP Luminova: Application Encryption Configuration
Choose the encryption handler, cipher, and options used by Luminova.
The Encryption Configuration class provides properties to configure default application cipher behaviors for data encryption and decryption.
These properties allow developers to specify the encryption driver, algorithm, method, digest, and key information used for encryption operations making it easier to work with Luminova\Security\Encryption\Crypter class.
See Encryption Implementations to get started with cryptography.
Class Definition
- Full namespace:
App\Config\Encryption - File path:
/app/Config/Encryption.php - This configuration derives from Luminova\Base\AbstractConfig.
- This class is final.
Properties
handler
Which encryption engine to use.
This allows you to specify the default application encryption driver to use (openssl or sodium).
- openssl is widely available and the default.
- sodium is built into
PHP 7.2+and requires libsodium1.0.14or higher.
public string $handler = 'openssl';Note:
This controls which library handles all encryption and decryption.If the required PHP extension is not loaded, or the installed libsodium version is too old, an
EncryptionExceptionis thrown.Every encrypted payload records the driver that created it. Switching
$handlerlater means payloads created by the previous driver can no longer be decrypted, and decryption fails with an unsupported driver error.
sodiumCipher
Sodium cipher algorithm selector.
Determines which libsodium construction is used when encrypting:
- secretbox →
sodium_crypto_secretbox_*(simple symmetric encryption) - aead →
sodium_crypto_aead_xchacha20poly1305_ietf_*(supports associated data)
// Can be string (`secretbox` or `aead`)
// or constant (`Sodium::SECRETBOX` or `Sodium::AEAD`)
public string $sodiumCipher = 'aead';Note:
This value controls encryption only.Decryption relies on the algorithm stored in the payload, not this config.
Associated data is not supported with
secretbox. Encrypting with associated data while this is set tosecretboxthrows anEncryptionException.This setting is ignored if you use
openssl.
method
The specific encryption algorithm when using OpenSSL.
The encryption mode for openssl (e.g., 'AES-128-CBC', 'AES-192-CBC', 'AES-128-CFB', 'AES-128-ECB', 'AES-256-GCM'). See documentation for more supported cipher methods
public string $method = 'AES-128-CBC';Note:
If you don't know which to pick, stick with
AES-128-CBC, it’s secureand widely supported.If this value is empty,AES-128-CBCis used.The method must also be supported by your OpenSSL installation, otherwise anEncryptionExceptionis thrown.Decryption uses the method stored in the payload.This setting is ignored if you use 'sodium'.
digest
Hashing algorithm used by the OpenSSL driver.
This allows you to specify the hashing digest to use (e.g., SHA512, SHA256). It is used in two places:
- As the hash for the HKDF that derives the encryption key from your application key.
- As the HMAC algorithm for
-HMAC-cipher methods whose name does not end inSHA1orSHA256. ForAES-128-CBC-HMAC-SHA256, for example, the algorithm in the cipher name is used instead.
public string $digest = 'SHA256';Note:
SHA512gives a longer hash (more collision-resistant), whileSHA256isslightly faster. Either is secure for most uses.Because the digest takes part in key derivation, changing it means data encrypted with the previous value can no longer be decrypted.This setting is ignored if you use 'sodium'.
keyInfo
Provides context information for the key derived in openssl encryption.
This value is passed as the info parameter to HKDF when the encryption key is derived from your application key.
public string $keyInfo = '';Note:
Leave it empty unless you know you need to customize it.Changing it means data encrypted with the previous value can no longer be decrypted.This setting is ignored if you use 'sodium'.