Results 1 to 9 of 9

Thread: encryption. [resolved]

  1. #1

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090

    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?
    Last edited by Acidic; May 8th, 2004 at 02:36 PM.
    Have I helped you? Please Rate my posts.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    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?
    Have I helped you? Please Rate my posts.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    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
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    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.
    Have I helped you? Please Rate my posts.

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    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
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    OK, i'll have a read. But are there also simpler methods?
    Have I helped you? Please Rate my posts.

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    It's not for that, but I've found I can use base64_encode(str) and base64_decode(str).
    Have I helped you? Please Rate my posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width