-
encryption. [resolved]
I'm quite sure there is an inbuild encryption function in PHP. What is it called and how do you use it? More importantly, will the string returned ever contain the character ";"? I need that character to seperate the items in the list, if the encrypted strings contains this character it'll obviously mess things up. Is there any character it never uses?
-
It depends on the cypher being used. PHP has two built in encrpytion functions : md5() and crypt().
MD5 uses the Message digest Algorithm and crypt uses DES. I'm not sure the exact output of these however a glance at their RFC's will soon tell you. Those fnctions are only one way encryption however. If you want two way encryption you'll need to use the mcrypt extension.
-
OK, I've found:
http://www.php.net/manual/en/functio...pt-generic.php
but when I run it it says:
Fatal error: Call to undefined function: mcrypt_module_open() in c:\documents and settings\sid karunaratne\my documents\acidic library - php\mailing list\send_mail.php on line 13
What's going on?
-
It requires the mcrypt extension. To enable it you can downloaded the library from here - its called libmcrypt.dll and place it in a system path directory. Then edit your php.ini and add the following line in the extensions section (it may already be there - in which case you just need to un comment it):
extension=php_mcrypt.dll
-
OK, I've done that, but now it won't decrypt it. I copy pasted the example from the link above exactly. Here it is anyway:
PHP Code:
<?
$key = "this is a secret key";
$input = "Let us meet at 9 o'clock at the secret place.";
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
echo "Encrypt: ".$encrypted_data;
echo "<br><br>";
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
mcrypt_generic_init($td, $key, $iv);
$decrypted_data = mdecrypt_generic($td, $encrypted_data);
echo "Decrypt: ".$decrypted_data;
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
?>
I seriously doubt that's where the error is though. I don't think it's a .dll file missing either as it doesn't give me any errors. The decrypted string is just the same as the encrypted string.
-
I'm not too clued up on encryption and I've never used the mcrypt functions in PHP. What I do know is that it can be very complex and probably requires some background reading before you dive in.
I found a tutorial which looks quite in depth and comprehensive:
http://hotwired.lycos.com/webmonkey/...tutorial1.html
-
OK, i'll have a read. But are there also simpler methods?
-
I don't think there is. If you are trying to encrypt the data for transfer over the web then it might be easier to set up SSL on your server.
-
It's not for that, but I've found I can use base64_encode(str) and base64_decode(str).