What are the best practices for integrating OpenSSL into a PHP website for encryption purposes?

To integrate OpenSSL into a PHP website for encryption purposes, it is best practice to use the OpenSSL functions provided by PHP to ensure secure encryption and decryption of data. This involves generating keys, encrypting data, decrypting data, and securely storing keys. It is important to use strong encryption algorithms and keep keys secure to prevent unauthorized access to sensitive information.

// Generate a new encryption key
$key = openssl_random_pseudo_bytes(32);

// Encrypt data using the generated key
$data = "Sensitive information";
$encrypted = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv);

// Decrypt data using the same key
$decrypted = openssl_decrypt($encrypted, 'aes-256-cbc', $key, 0, $iv);

// Store the key securely (e.g. in a database or using a secure key management system)