phpvariablesencryptioncryptographymd5

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.


Solution

  • 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.