Reputation: 37
i'm having some trouble decrypting a string that was encrypted using openssl. I don't have access to change the encryption code, but i do have read access:
Encrypt code (unable to modify)
<?php
$key = hex2bin("24a5d2b96b9aee2fb515c94fb36da508");
$encryptTxt = openssl_encrypt(
"txt to encrypt",
'AES-128-ECB',
$key
);
?>
<a href="decrypt.php?un=<?php echo bin2hex(base64_decode($encryptTxt)) ?>">link</a>
Here is how I have attempted to decrypt:
decrypt.php
$ciphertext = $_GET['un'];
$cipher = "aes-128-ecb";
$key = hex2bin("24a5d2b96b9aee2fb515c94fb36da508");
$original_plaintext = openssl_decrypt($ciphertext, $cipher, $key);
echo "text= " . $original_plaintext;
The decrypted text is not returned on the decrypt page
Upvotes: 1
Views: 512
Reputation: 37
SOLVED: I updated decrypt.php to the following and it returned the decrypted text
$ciphertext = $_GET['un'];
$ciphertext = hex2bin($ciphertext);
$ciphertext = base64_encode($ciphertext);
$cipher = "aes-128-ecb";
$key = hex2bin("24a5d2b96b9aee2fb515c94fb36da508");
$original_plaintext = openssl_decrypt($ciphertext, $cipher, $key);
echo "text= " . $original_plaintext;
Upvotes: 1