Page 1 of 1

Php Encryption Algorithms -- Help Needed!!!

Posted: Mon May 07, 2007 7:30 pm
by vamsinadella
Hi all,

In my application, I'm trying to encrypt a certain string and send it back to the user by email. Currently i'm using SHA(1). I tried SHA and MD5 also. The problem with these is they give a really long (40 characters) encrypted string. The users are freaking out seeing such a big string. To make things worst, i lao have to append thier company name to it which make it even bigger. So i need an alorithm that can generate a smaller string like 6, 8 or evejn 10 is fine.

I browsed around and forund somethng called Crypt(). But this returns a binary output and hence sometimes it has special characters in it. Other than this fact this works very well.

Can anyone help me with an algorithm that returns a small string and is not binary(i do not want any special characters in it.) Numbers and alphabets only.

Any help is appreciated. I have been searching a lot. Thanks.

-- Vamsi.

Posted: Tue May 08, 2007 1:34 am
by stereofrog
Can you tell us a bit more on what you're trying to achieve?

Posted: Tue May 08, 2007 9:35 am
by feyd
You should be aware that the shorter the result is, the more likely it will match another you have already generated. If you don't really care about the raised collision rate you can choose other hashes such as CRC.

crc32()

Posted: Tue May 08, 2007 3:53 pm
by vamsinadella
stereofrog,

Thank you for responding.

I'm trying to encrypt a string. For ex. say we have a string "This is an example string" and i have to send this string to a user. But i do not want to send it as it is so i want to encrypt it. to achieve that we can use many php functions like SHA(), SHA1(), MD5() Crypt(). BUt the problem (my problem) with these functions is they either give you a long 40 or a 32 character string or it is binary - meaning it spits out special characters every now and then.

I 'm looking for an encryption algorithm that is not too long (may be 10 - 12 characters) and do not have any special characters. Does that make sense??? I'm sorry i'm trying my best to put my problem as clear as possible.

Feyd,

First of all, thanks you for the help. Yes i do realize that the shorter it is the more likely it will match. But the users are bent upon getting a shorter string. I tried crc32(). It is giving me just numbers....Is it the way it is supposed to work??? i mean that is ok. But it is spitting a '-' sign sometimes. Is there a way to avoid this? Thanks. Any other functions in PHP you have in mind?

-- Vamsi

Posted: Tue May 08, 2007 7:04 pm
by feyd
crc32() + dechex() maybe... eight hex characters should result.

Posted: Tue May 08, 2007 7:12 pm
by Begby
Are you trying to make it so the user can then decrypt this string later on? Also does it involve a credit card number per chance?

Re: Php Encryption Algorithms -- Help Needed!!!

Posted: Tue May 08, 2007 7:18 pm
by AKA Panama Jack
vamsinadella wrote:The users are freaking out seeing such a big string.
Boy, it doesn't take much to freak them out. :D They would go completely catatonic if they saw a URL from my sites blogging system. :D

http://panamajack.aatraders.com/readblog/19d98afc3721302b70501ac278a35672b6feac6ef4d7a61277be10391032a22ffd37cfd3e77b1e0431a380ae6d97e724

It contains alot of info and created using mcrypt.

Re: Php Encryption Algorithms -- Help Needed!!!

Posted: Tue May 08, 2007 7:29 pm
by Begby
AKA Panama Jack wrote:
vamsinadella wrote:The users are freaking out seeing such a big string.
Boy, it doesn't take much to freak them out. :D They would go completely catatonic if they saw a URL from my sites blogging system. :D

http://panamajack.aatraders.com/readblog/19d98afc3721302b70501ac278a35672b6feac6ef4d7a61277be10391032a22ffd37cfd3e77b1e0431a380ae6d97e724

It contains alot of info and created using mcrypt.
Enlighten me panama jack... how much info can you put in that string? What kind of stuff do you have in there? This might be a solution to a problem I am having.