Veronica's Encryption / Decryption Demonstration

String to be Encrypted


Encrypted String

GOTO Decrypt

Instructions: Enter a phrase in the "String to be Encrypted" box. Click Encrypt. Copy the encrypted string. Click the GOTO Decrypt link. In that form, paste the encrypted string into the "Encrypted String" box. Click Decrypt to see your original phrase decrypted.

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 (www.n-able.com/blog/aes-256-encryption-algorithm)

 

CODE FOLLOWS

<?php

include('includes/header.php');

// set error reporting to all
error_reporting(E_ALL);

// variables
$self basename($_SERVER['SCRIPT_NAME']);
$string = isset($_POST['string']) ? $_POST['string'] : "Once you choose hope, anything is possible.";
$action 'encrypt';
$encrypted encrypt_decrypt($action$string);

?>

<h1> Veronica's Encryption / Decryption Demonstration</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_form.php">GOTO Decrypt</a>

<p>
    Instructions: Enter a phrase in the "String to be Encrypted" box.
    Click Encrypt. Copy the encrypted string. Click the GOTO Decrypt link.
    In that form, paste the encrypted string into the "Encrypted String" box.
    Click Decrypt to see your original phrase decrypted.
</p>

<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>

<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 (www.n-able.com/blog/aes-256-encryption-algorithm)
</div>

</p>

<?php

// functions

function encrypt_decrypt($action$string)
{

    
$output false;
    
$encrypt_method "AES-256-CBC";

    
// the following two values were updated
    
$secret_key 'clavis abscondita';
    
$secret_iv 'nuntius mutans';

    
// hash
    
$key hash('sha256'$secret_key);

    
// encrypt method AES-256-CBC expects 16 bytes.
    
$iv substr(hash('sha256'$secret_iv), 016);

    if (
$action == 'encrypt')
    {
        
$output base64_encode(openssl_encrypt($string$encrypt_method$key0$iv));
    }
    else
    {
        if (
$action == 'decrypt')
        {
            
$output openssl_decrypt(base64_decode($string), $encrypt_method$key0$iv);
        }
    }
    return 
$output;
}

include(
'includes/footer.php');

?>