How can PHP developers utilize OpenSSL functions to encrypt and decrypt sensitive data, such as passwords, in a secure manner?

PHP developers can utilize OpenSSL functions to encrypt and decrypt sensitive data, such as passwords, by using strong encryption algorithms and securely managing encryption keys. By generating a random encryption key, encrypting the data with this key, and then securely storing or transmitting the encrypted data along with the key, developers can ensure that the data remains secure. To decrypt the data, developers can use the same encryption key to reverse the encryption process and retrieve the original sensitive data.

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

// Encrypt the sensitive data with the encryption key
$encryptedData = openssl_encrypt($sensitiveData, 'AES-256-CBC', $encryptionKey, 0, $iv);

// Store or transmit the encrypted data and encryption key securely

// Decrypt the encrypted data using the encryption key
$decryptedData = openssl_decrypt($encryptedData, 'AES-256-CBC', $encryptionKey, 0, $iv);

// Use the decrypted data as needed