How can the issue of extra characters in the PHP encryption output be resolved?

Issue: The extra characters in PHP encryption output can be resolved by using base64_encode() and base64_decode() functions to encode and decode the encrypted data. This will ensure that the output is in a format that does not contain any extra characters.

// Encrypt data
$data = "Hello World";
$encryption_key = "secret_key";
$encrypted_data = openssl_encrypt($data, 'AES-256-CBC', $encryption_key, 0, 'randomiv');

// Encode encrypted data using base64
$encoded_data = base64_encode($encrypted_data);

// Decode encrypted data using base64
$decoded_data = base64_decode($encoded_data);

// Decrypt data
$decrypted_data = openssl_decrypt($decoded_data, 'AES-256-CBC', $encryption_key, 0, 'randomiv');

echo $decrypted_data; // Output: Hello World