What are the potential security risks involved in encrypting and decrypting data using PHP and JavaScript?

When encrypting and decrypting data using PHP and JavaScript, one potential security risk is the exposure of encryption keys in client-side JavaScript code, making them vulnerable to being accessed by malicious actors. To mitigate this risk, it is recommended to handle encryption and decryption operations solely on the server-side using PHP, and only sending encrypted data to the client-side for display or storage.

// Server-side encryption and decryption using PHP
function encryptData($data, $key) {
    return openssl_encrypt($data, 'AES-256-CBC', $key, 0, $key);
}

function decryptData($data, $key) {
    return openssl_decrypt($data, 'AES-256-CBC', $key, 0, $key);
}