Thank you very much. OK maybe I dont know how to encrypt and decrypt! 
I have two php scripts one encrypts and the other decrypts
Code:
<?php
// Designate string to be encrypted
$string = "Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference.";
// Encryption/decryption key
$key = "Four score and twenty years ago";
// Encryption Algorithm
$cipher_alg = MCRYPT_RIJNDAEL_128;
// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND);
// Output original string
print "Original string: $string <p>";
// Encrypt $string
$encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_CBC, $iv);
// Convert to hexadecimal and output to browser
print "Encrypted string: ".bin2hex($encrypted_string)."<p>";
print "Decrypted string: $decrypted_string <p>";
?>
the other
Reads the file where the encrypted data is saved and then tries to decrypt it :
Code:
<?php
// Designate string to be encrypted
$string = "Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference.";
// Encryption/decryption key
$key = "Four score and twenty years ago";
// Encryption Algorithm
$cipher_alg = MCRYPT_RIJNDAEL_128;
// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND);
// Output original string
$lines = file('data.txt');
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
$decrypted_string = mcrypt_decrypt($cipher_alg, $key, $line, MCRYPT_MODE_CBC, $iv);
echo "Line #<b>{$line_num}</b> : " . $decrypted_string . "<br />\n";
}
?>
I understand that everytime I encrypt the data its not the same. But how do I get the data back ?
Bookmarks