shorter php cipher than md5?

tiredofcoding picture tiredofcoding · Sep 21, 2010 · Viewed 21.9k times · Source

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.

Answer

Codebutcher picture Codebutcher · Feb 19, 2015

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);