<?php
function sslencrypt($source, $algo, $key, $opt, $iv) {
$encstring = openssl_encrypt($source, $algo, $key, $opt, $iv);
return $encstring;
}
function ssldecrypt($encstring, $algo, $key, $opt, $iv) {
$decrstring = openssl_decrypt($encstring, $algo, $key, $opt, $iv);
return $decrstring;
}
// string to be encrypted
$source = "PHP: Hypertext Preprocessor";
// Display the original string
echo "Before encryption: " . $source . "\n";
$algo = "BF-CBC";
$opt=0;
$ivlength = openssl_cipher_iv_length($algo);
$iv = random_bytes($ivlength);
$key = "abcABC123!@#";
// Encryption process
$encstring = sslencrypt($source, $algo, $key, $opt, $iv);
// Display the encrypted string
echo "Encrypted String: " . $encstring . "\n";
// Decryption process
$decrstring = ssldecrypt($encstring, $algo, $key, $opt, $iv);
// Display the decrypted string
echo "Decrypted String: " . $decrstring;
?>