3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $algo = 'aes-256-gcm'; $iv = random_bytes(openssl_cipher_iv_length($algo)); $key = random_bytes(32); // 256 bit $data = random_bytes(256); // 1 Kb of random data //$data = ""; $ciphertext = openssl_encrypt( $data, $algo, $key, OPENSSL_RAW_DATA, $iv, $tag ); // Change 1 bit in ciphertext // $i = rand(0, mb_strlen($ciphertext, '8bit') - 1); // $ciphertext[$i] = $ciphertext[$i] ^ chr(1); echo(base64_encode($ciphertext)); echo("\n"); echo(mb_strlen($ciphertext, '8bit')); echo("\n"); $decrypt = openssl_decrypt( $ciphertext, $algo, $key, OPENSSL_RAW_DATA, $iv, $tag ); if (false === $decrypt) { throw new Exception(sprintf( "OpenSSL error: %s", openssl_error_string() )); } printf ("Decryption %s\n", $data === $decrypt ? 'Ok' : 'Failed');
Output for 7.1.7
Xkq06Z1yKraNgsetXnc2fLHvsExMZpcfGQ7omYfrg0piTWCAi8U18sebprNT03UKnh45m0d0JPh5B9uj+2DeBvmMdBwyO567YM3rB85aEpbPdjLVR83gTXoLznCZ8xlE1dkqD1mmbGFb9iNU3DL6e9U+WnfRkSjWd2DDjZ+TVtC5so9Age7wHdNSBpaf5ny0gqFzTKuNw8M4TgunTtsz2pHn6ulcP27fB+UTZn++0hMKm9AKT3bETa9GFpuKN4iJkUng27DGAr/83zgdAZ2pcEgmTYg4aMMenxZNAF19ig6kcSxnt0l6xgR/7Btg4Exp4dLt5neWBCWI1Nsk5dWi9g== 256 Decryption Ok