encode data in md5 (or similar)
Moderator: General Moderators
encode data in md5 (or similar)
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.
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:
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.
As for how to hash this using MD5:
Code: Select all
$hash = md5($timestamp . $unique_id);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.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
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).
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: encode data in md5 (or similar)
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.GeXus wrote:would anyone have suggestions for the best way to encode this in php? so that later i can decode it.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Re: encode data in md5 (or similar)
Decimal is often quite longer actually, and varies in length. Binary however is always half the length of the hex string of a hash.superdezign wrote:In fact, you could just convert back and forth from hexadecimal and decimal if you must shorten the string.