What are the advantages and disadvantages of storing encryption keys in the application code versus in the database in PHP?
Storing encryption keys in the application code can provide better security as the keys are not directly accessible to database administrators. However, storing keys in the database can make it easier to manage and rotate keys when necessary. It is recommended to use a combination of both methods, storing the keys in the application code and periodically rotating them in the database for added security.
// Storing encryption key in the application code
define('ENCRYPTION_KEY', 'my_secret_key');
// Retrieving encryption key from the database
$encryptionKey = $db->query('SELECT encryption_key FROM keys_table')->fetchColumn();