Page 1 of 1
encode data in md5 (or similar)
Posted: Tue Sep 25, 2007 4:37 pm
by GeXus
I'd like to take two values, one a datetime stamp and one a unique id (which could range from 1-100,000)... and encode them into a hash of some kind.... ideally the shorter the better.... would anyone have suggestions for the best way to encode this in php? so that later i can decode it.
Posted: Tue Sep 25, 2007 4:45 pm
by EricS
The final size of the hash is completely dependent on the hashing algorithm. The final hash size for any amount of data being hashed changes very little (only by a character or two) for most hashing algorithms. So md5 for instance. If you hash 100MBs of data or 10 KBs of data, the resulting hash size is still a 32 character hexidecimal value.
As for how to hash this using MD5:
Code: Select all
$hash = md5($timestamp . $unique_id);
Edit: Opps I missed the very last sentence. Hashes can not be decoded later. You can only rehash values and compare the hashes for equality. If decoding is what you want. Then encryption (not hashing) is what you seek. Look up Blowfish, AES, DES for examples.
Posted: Tue Sep 25, 2007 8:24 pm
by cade
hey guys...it's good news for me today. The coldfusion function for hash works the same as our md5. This is really good news
Posted: Wed Sep 26, 2007 2:58 am
by onion2k
cade wrote:hey guys...it's good news for me today. The coldfusion function for hash works the same as our md5. This is really good news
If you hash data you will not be able to 'unhash' it. A hashing algorithm is always one way only. You want an encryption algorithm instead if you want to be able to get the original data back again.
You should also be aware that MD5 is somewhat flawed. It's not really a big deal for most people, but there are better alternatives around (for PHP anyway (
SHA256), I can't speak for ColdFusion).
Re: encode data in md5 (or similar)
Posted: Wed Sep 26, 2007 7:34 am
by superdezign
GeXus wrote:would anyone have suggestions for the best way to encode this in php? so that later i can decode it.
You seem to have confused hashing with encryption, as onion has stated. Both PHP and MySQL have built-in encryption algorithms, but from the sound of what you are doing, you probably don't *actually* need one. In fact, you could just convert back and forth from hexadecimal and decimal if you must shorten the string.
Re: encode data in md5 (or similar)
Posted: Wed Sep 26, 2007 9:52 am
by feyd
superdezign wrote:In fact, you could just convert back and forth from hexadecimal and decimal if you must shorten the string.
Decimal is often quite longer actually, and varies in length. Binary however is always half the length of the hex string of a hash.