Are there existing methods or libraries in PHP for encrypting and decrypting email addresses for secure transmission?

Encrypting and decrypting email addresses for secure transmission can be achieved using various encryption algorithms such as AES or RSA. One common approach is to encrypt the email address before sending it and decrypt it on the receiving end to ensure secure transmission. PHP provides libraries like OpenSSL for encryption and decryption tasks.

// Encrypt email address
function encryptEmail($email, $key) {
    return openssl_encrypt($email, 'aes-256-cbc', $key, 0, '1234567890123456');
}

// Decrypt email address
function decryptEmail($encryptedEmail, $key) {
    return openssl_decrypt($encryptedEmail, 'aes-256-cbc', $key, 0, '1234567890123456');
}

// Usage
$email = 'test@example.com';
$key = 'secretkey';

$encryptedEmail = encryptEmail($email, $key);
echo 'Encrypted Email: ' . $encryptedEmail . PHP_EOL;

$decryptedEmail = decryptEmail($encryptedEmail, $key);
echo 'Decrypted Email: ' . $decryptedEmail . PHP_EOL;