Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shorter php cipher than md5?

For a variety of stupid reasons, the maximum length of a given form variable that we are posting to an external server is 12 characters.

I wanted to obscure that value with md5, but obviously with 12 characters that isn't going to work. Is there a cipher with an already-made PHP function which will result in something 12 characters or less?

The security and integrity of the cipher isn't super important here. My last resort is to just write a function which moves each letter up or down an ascii value by x. So the goal isn't to obscure it from a cryptography expert, but just to not post it in plain text so a non-technical worker looking at it won't know what it is.

Thanks for any advice.

like image 961
tiredofcoding Avatar asked Sep 21 '10 19:09

tiredofcoding


People also ask

Is MD5 a weak cipher?

For over 17 years, cryptographers have been recommending against the use of MD5. MD5 is considered weak and insecure; an attacker can easily use an MD5 collision to forge valid digital certificates.

What hashing algorithm does PHP use?

PHP has a total of 46 registered hashing algorithms among which “sha1”, “sha256”, “md5”, “haval160, 4” are the most popular ones. $string: This parameter expects the string to be hashed. $getRawOutput: This optional parameter expects a boolean value, on TRUE the function returns the hash in a raw binary format.

Does PHP support sha256?

PHP offers the built-in function hash() . The first argument to the function is the algorithm name (you can pass algorithm names like sha256, sha512, md5, sha1, and many others).

Why MD5 is used in PHP?

Definition and Usage The md5() function uses the RSA Data Security, Inc. MD5 Message-Digest Algorithm. From RFC 1321 - The MD5 Message-Digest Algorithm: "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input.


Video Answer


3 Answers

maybe this will help you generate a 12 char string that you can pass in a URL, without increasing the risk of collisions

substr(base_convert(md5($string), 16,32), 0, 12); 
like image 82
Codebutcher Avatar answered Oct 22 '22 08:10

Codebutcher


This is an addition to this answer.

The answer proposes to take the first twelve characters from a 32 character representation of md5. Thus 20 characters of information will be lost - this will result in way more possible collisions.

You can reduce the loss of information by taking the first twelve characters of a 16 character representation (the raw form):

substr(md5($string, true), 0, 12);

This will maintain 75% of the data, whereas the use of the 32 char form only maintains 37.5% of the data.

like image 29
NikiC Avatar answered Oct 22 '22 09:10

NikiC


Try crc32() maybe?

like image 26
Alex Howansky Avatar answered Oct 22 '22 09:10

Alex Howansky