Don Alexander Eckford's Decryption Demo

Encrypted String


Decrypted String

GOTO Encrypt
 

CODE FOLLOWS

<?php
    
include('includes/header.php');

    
// code
    
error_reporting(E_ALL);    // set error reporting to all
    
$self basename($_SERVER['SCRIPT_NAME']);

    
$encrypted = isset($_POST['encrypted']) ? $_POST['encrypted'] : "";

    
$action 'decrypt';
    
$decrypted encrypt_decrypt($action$encrypted);

    
?>

    <h1> Don Alexander Eckford's Decryption Demo</h1>

    <form action="<?php echo($self); ?>" method="POST">

        <fieldset>
            <legend>Encrypted String</legend>

            <label>
    <textarea rows="10" cols="120" type="text" name="encrypted" value="<?php echo($encrypted); ?>">
    <?php echo($encrypted); ?>
    </textarea>
            </label>
            <br>
        </fieldset>

        <br> <br>

        <fieldset>
            <legend>Decrypted String</legend>
            <label>
    <textarea rows="10" cols="120" type="text" name="decrypted" value="">
    <?php echo($decrypted); ?>
    </textarea>
            </label>
            <br>
        </fieldset>

        <p>
            <input type="submit" name="submit" value="Decrypt">
        </p>

    </form>

    <a href="encrypt.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_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), 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');
?>