Tedd's Encryption/Decryption Demo
GOTO Decrypt
To understand more about this Encryption method (AES-256-CBC) see:
Review this article.
"AES would take billions of years to break using current computing technology.
Hackers would be foolish to even attempt this [brute-force] type of attack." -- taken from above article
CODE FOLLOWS
<?php
include('includes/header.php');
// code
error_reporting(E_ALL); // set error reporting to all
$self = basename($_SERVER['SCRIPT_NAME']);
$string = isset($_POST['string']) ? $_POST['string'] : "Now is the time.";
$action = 'encrypt';
$encrypted = encrypt_decrypt($action, $string);
?>
<h1> Tedd's Encryption/Decryption Demo</h1>
<form action="<?php echo($self); ?>" method="POST">
<fieldset>
<legend>String to be Encrypted</legend>
<textarea rows="10" cols="120" type="text" name="string" value="<?php echo($string); ?>">
<?php echo($string); ?>
</textarea>
<br>
</fieldset>
<br> <br>
<fieldset>
<legend>Encrypted String</legend>
<textarea rows="10" cols="120" type="text" name="encrypted" value="">
<?php echo($encrypted); ?>
</textarea>
<br>
</fieldset>
<p>
<input type="submit" name="submit" value="Encrypt">
</p>
</form>
<a href="decrypt.php">GOTO Decrypt</a>
<p>
To understand more about this Encryption method (AES-256-CBC) see:
<a href="https://www.n-able.com/blog/aes-256-encryption-algorithm"> Review this article. </a>
</p>
<p>
<div class="blue">
"AES would take billions of years to break using current computing technology.
Hackers would be foolish to even attempt this [brute-force] type of attack." -- taken from above article
</div>
</p>
<?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_iv = 'non sum qualis eram';
// 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');
?>