tags:

views:

24

answers:

1

please don't mind me asking this but I'm new to php and I need to encrypt and decrypt a password. I want to send the password over a URL so I heard it's the safest way to use mycrypt.

I don't get the thing with the KEY in the mycrypt function? Shouldn't that be as secret as the password itself. e.g. I'm using this function from the PHP manual:

    <?php
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $key = "this is my personal decryption key";
    $text = "Meet me at 11 o'clock behind the monument.";
    echo strlen($text) . "\n";

    $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
    echo strlen($crypttext) . "\n";
    ?>

can i set the $key to whatever i want? what if someone downloads the source of my document where i set up this $key. he is able to easily decrypt the $text again. isn't he? Or do i get something wrong with this function?

+1  A: 

It would probably be simpler and more secure to use TLS (HTTPS). This can use the same technologies (e.g. AES/Rijndael), but handles many of the details, including key distribution, for you. If you use mcrypt, you need to figure out a safe way to exchange both key and IV (initialization vector).

You clearly also need to protect the key and IV. So if it's embedded in your PHP file, you must take care to secure that file. It's important to remember the distinction between server and client side, though. The key won't leak into the generated HTML file unless you have a bug in your script.

Matthew Flaschen
but I can (easily) download a .php file form a server and simply view the source code. i read the key and decrypt it.i need a simple way to encrypt a password, hang it to a url, read it with $_get, then decrypt it and pass it on. ?? TLS (HTTPS) sounds to complicated for me. I'm a rookie in programming.
You can't directly download the active PHP source code from another person's server, unless they have a bug. HTTPS is actually not too complicated, since the web server does most of the work for you. What server are you running on the receiving end?
Matthew Flaschen
I'm on a ZEUS Server. i thought it might be possible to suck php files from a server with apps like sitesucker or file2hd.com
You would be viewing the output of the PHP file (HTML), not the source code. As Matthew Flaschen states the only way that could happen is if the server is misconfigured or not properly secured.
laz
Those sites let you download the generated HTML content, not the actual PHP. I found this [user guide](http://support.zeus.com/zws/media/docs/4.3/ZWSUserGuide.pdf), which has a section (4.10, on p. 68), about setting up SSL/HTTPS on Zeus.
Matthew Flaschen