How can the generation of the initialization vector (IV) be improved in the PHP encryption code to ensure consistency with Swift encryption?

The issue with the current initialization vector (IV) generation in the PHP encryption code is that it might not be consistent with the IV generation in Swift encryption. To ensure consistency, we can explicitly set the IV in PHP to match the IV generated in Swift. This way, both encryption processes will use the same IV, leading to consistent encryption results.

// Generate a fixed IV to ensure consistency with Swift encryption
$iv = hex2bin('00000000000000000000000000000000');

// Encrypt data using the fixed IV
$cipher = 'AES-128-CBC';
$key = 'your_secret_key';
$data = 'Hello, World!';
$encrypted = openssl_encrypt($data, $cipher, $key, OPENSSL_RAW_DATA, $iv);

// Decrypt data using the same fixed IV
$decrypted = openssl_decrypt($encrypted, $cipher, $key, OPENSSL_RAW_DATA, $iv);

echo $decrypted; // Output: Hello, World!