encryption...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

encryption...

Post by pedroz »

Hi...

I am using the code above to use in url.
Example:

Code: Select all

$code=public_encrypt("ref_123|bill@hotmail.com");

echo "<a href=http://mysite.com/contact/$code>support</a>";


$td = MCRYPT_RIJNDAEL_256;
$tdpub = MCRYPT_3DES;
$iv_size = mcrypt_get_iv_size($td, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);


function public_encrypt($data){
    global $tdpub, $iv_size, $iv;
    $key="mykey";
    $encrypted_data = mcrypt_encrypt($tdpub, $key, $data, MCRYPT_MODE_ECB, $iv);
    $encrypted_data = bin2hex($encrypted_data);
        return ($encrypted_data);
}


function public_decrypt($data){
    global $tdpub, $iv_size, $iv;
    $key="mykey";
    $encrypted_data = hex2bin($data);
    $decrypted_data = mcrypt_decrypt($tdpub, $key, $encrypted_data, MCRYPT_MODE_ECB, $iv);
    return trim($decrypted_data);
}
PROBLEM:
I am getting a $code result in public_encrypt very large if emails are too long...
public_encrypt("ref_123|bill.gates.sucks@hotmail.com");
http://mysite.com/contact/b81470b62e92a ... 4176a4b5b5

Do you have any idea for a simple string encryption(+decrypt) function giving me a small result?
- it does not to be very strong.
- i thought in base64_encode/base64_decode but i have some problems with /+= chars received from base64_encode funciton...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

is there a reason you need to decrypt it? What's the goal of this code?
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

It's a way to send specialized data that can't be seen by anyone. We use something similar on our game website.

http://panamajack.aatraders.com/readblo ... d3dd134510

That is a link to my blog. The dac91775fd510be6a394e6030b0aebb2c50e85d3dd134510 is encoded information about the information that should be displayed. Also, by using an encoded string such as this instead of something like ?var=1&var2=this will cause the search engines to index the page better and follow more links. Some search engines will follow more links on a site if they are encoded like this.

For predoz...

Why are they too long? Does the host or server you are using have a force limit on URL size? Most server installs have an incredably long default url length.

And using most encryption techniqes will result in long strings even if they are compressed because the compressed data has to be converted into a text string to be used in a URL.
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

Post by pedroz »

AKA Panama Jack wrote: For predoz...

Why are they too long? Does the host or server you are using have a force limit on URL size? Most server installs have an incredably long default url length.
It is not a question of the host server...
The main idea is to provide a link to share between members avoiding mysql connections.

For example,
1. I send you a link http://mysite.com/contact/54iu243u243uy432iuy4
2. You click on link and it will display a form and you will be able to write the message on the form
Email stay encrypted in <input type=hidden name=email value=3553tTRErtretetr>
(this process will avoid multiple mysql connections)

It will be interesting to find a solution to provide a short url...
However if it is not possible, I think I would have to follow the mysql connection solution putting the member number in the link...
$code=public_encrypt("ref_123|1"); instead...
$code=public_encrypt("ref_123|bill@hotmail.com");

Any ideas?
Post Reply