It sounds an easy task but I'm still learning. I have a textarea where I put data and I want to post it to a php script to decrypt it.
Here is my HTML:
 <html>
    <form action="php.php" method="post">
    <textarea id="input" name="input" rows="4" cols="50"</textarea>
    <input type="submit" name="decrypt" class="button" value="decrypt" />
    </form>
    
    <p><?php echo $decrypt; ?></p>
    
    </html>
PHP Code:
<?php
function Decrypt($ciphertext)
{
    $key = 1;
    $c = base64_decode($ciphertext);
    $ivlen = openssl_cipher_iv_length($cipher = "AES-128-CBC");
    $iv = substr($c, 0, $ivlen);
    $hmac = substr($c, $ivlen, $sha2len = 32);
    $ciphertext_raw = substr($c, $ivlen + $sha2len);
    $original_plaintext = openssl_decrypt($ciphertext_raw, $cipher, $key, OPENSSL_RAW_DATA, $iv);
    $calcmac = hash_hmac('sha256', $ciphertext_raw, $key, true);
    if (hash_equals($hmac, $calcmac)) {
        return $original_plaintext;
    }
}
   
if (!empty($_POST)) {
    $decrypt = Decrypt($_POST['decrypt']);
    print_r($_POST);
}
Error I'm receiving "Warning: Undefined array key "decrypt" on line20"
Expected behavior: Output the original plaintext.
If you would like to test a valid encrypted line please use:
W9aMvbRmmN/52Kmv1rr9i59ecKu2KYIhrL+Mj+dD8VE3BtwUiFIEBqrRc/e3aw8li2GKKu4B3FVyx/dkRnNnmw==
 
    