Veronica's Decryption Demonstration
GOTO Encrypt
 
<?php
include('includes/header.php');
// set error reporting to all
error_reporting(E_ALL);
$self = basename($_SERVER['SCRIPT_NAME']);
$encrypted = isset($_POST['encrypted']) ? $_POST['encrypted'] : "";
$action = 'decrypt';
$decrypted = encrypt_decrypt($action, $encrypted);
?>
<h1> Veronica's Decryption Demonstration</h1>
<form action="<?php echo($self); ?>" method="POST">
<fieldset>
<legend>Encrypted String</legend>
<textarea rows="10" cols="120" type="text" name="encrypted" value="<?php echo($encrypted); ?>">
<?php echo($encrypted); ?>
</textarea>
<br>
</fieldset>
<br> <br>
<fieldset>
<legend>Decrypted String</legend>
<textarea rows="10" cols="120" type="text" name="decrypted" value="">
<?php echo($decrypted); ?>
</textarea>
<br>
</fieldset>
<p>
<input type="submit" name="submit" value="Decrypt">
</p>
</form>
<a href="encrypt_form.php">GOTO Encrypt</a>
<?php
// ======== functions ============
function encrypt_decrypt($action, $string)
{
$output = false;
$encrypt_method = "AES-256-CBC";
// the following two values should be changed for your personal use.
// $secret_key = 'Epur si muove';
$secret_key = 'clavis abscondita';
// $secret_iv = 'non sum qualis eram';
$secret_iv = 'nuntius mutans';
// hash
$key = hash('sha256', $secret_key);
// encrypt method AES-256-CBC expects 16 bytes.
$iv = substr(hash('sha256', $secret_iv), 0, 16);
if ($action == 'encrypt')
{
$output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
}
else
{
if ($action == 'decrypt')
{
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
}
}
return $output;
}
include('includes/footer.php');
?>