OpenSSL Encryption

Text to encrypt : ' . $source . '

'; $cipher = "aes-128-gcm"; //$ivlen = openssl_cipher_iv_length( $cipher ); $iv = str_pad( 'Desperately', 16 ); //openssl_random_pseudo_bytes( $ivlen ); $ivhex = bin2hex( $iv ); $pass = 'Seeking Susan'; $key = bin2hex( $pass ); //openssl_random_pseudo_bytes( $i, $cstrong ); echo "iv in plaintext to use : " . $iv . '
'; echo "password in plaintext to use : " . $pass . '
'; echo '
'; echo "iv in hex to use : " . $ivhex . '
'; echo "password in hex to use : " . $key . '
'; echo '

'; $ciphertext = openssl_encrypt( $source, $cipher, $key, $options=0, $ivhex, $tag ); file_put_contents ( './ciphertext.encrypted', $ciphertext ); //store $cipher, $iv, and $tag for decryption later $ciphertext = file_get_contents( './ciphertext.encrypted' ); $original_source = openssl_decrypt( $ciphertext, $cipher, $key, $options=0, $ivhex, $tag ); echo '

Decrypted text : ' . $original_source . '

'; ?>

PHP code as textfile

Source ➠ http://php.net/manual/en/function.openssl-encrypt.php