<?phppublicfunctionencrypt($text,$key){if(strlen($key)!==32){thrownewException("Key must be 32 bytes long.");}$iv=openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));$encrypted=openssl_encrypt($text,'aes-256-cbc',$key,OPENSSL_RAW_DATA,$iv);if($encrypted===false){thrownewException("Encryption failed.");}$data=$iv.$encrypted;returnbase64_encode($data);}publicfunctiondecrypt($data,$key){if(strlen($key)!==32){thrownewException("Key must be 32 bytes long.");}$data=base64_decode($data);$iv=substr($data,0, openssl_cipher_iv_length('aes-256-cbc'));$encrypted=substr($data, openssl_cipher_iv_length('aes-256-cbc'));$decrypted=openssl_decrypt($encrypted,'aes-256-cbc',$key,OPENSSL_RAW_DATA,$iv);if($decrypted===false){thrownewException("Decryption failed.");}return$decrypted;}