I have a 3 php file one is index.php
where the original string is there, encrypt.php
where will i encrypt the original string and lastly the decrypt.php
where will i decrypt it but the problem is when i try to decrypt it the result is still encrypted but not the same encrypt it's different. Can someone help me about the decryption?
here is the picture i click the encrypt
here is the decrypted this is the problem the output should be "fwf2" but it's different
here is the code for index.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="POST" action="encrypt.php">
Original String <input type="text" name="text">
<input type="submit" name="encrypt" value="Encrypt" href="encrypt.php">
</form>
</body>
</html>
here is the encrypt.php
<?php
$secret_key = "thisismykey12345";
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
if(isset($_POST['encrypt'])){
$string = $_POST['text'];
$encrypted_string = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $secret_key, $string, MCRYPT_MODE_CBC, $iv);
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="POST" action="decrypt.php">
Encrypted String <input type="text" style="width:500px;" name="encrypted" value="<?php echo $encrypted_string; ?>">
<input type="submit" name="decrypt" value="Decrypt" href="decrypt.php">
</body>
</html>
here is the decrypt.php
<?php
$secret_key = "thisismykey12345";
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
if(isset($_POST['decrypt'])){
$encrypted_string = $_POST['encrypted'];
$decrypted_string = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $secret_key, $encrypted_string, MCRYPT_MODE_CBC, $iv);
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="POST" action="encrypt.php">
Decrypted String <input type="text" name="decrypted" style="width:500px;" value="<?php echo $decrypted_string ?>">
</body>
</html>