What is the difference between MD5 hashing and encryption in PHP?

MD5 hashing is a one-way cryptographic function that converts input data into a fixed-size string of characters, which cannot be reversed to obtain the original input. Encryption, on the other hand, is a two-way process that transforms data into a format that can be decrypted back to its original form using a key. In PHP, MD5 hashing is commonly used for storing passwords securely, while encryption is used for securing sensitive data during transmission or storage.

// MD5 hashing example
$password = "mysecurepassword";
$hashed_password = md5($password);
echo "Hashed password: " . $hashed_password;

// Encryption example
$data = "sensitivedata";
$key = "myencryptionkey";
$encrypted_data = openssl_encrypt($data, 'AES-256-CBC', $key, 0, 'myinitializationvector');
echo "Encrypted data: " . $encrypted_data;