Wednesday, December 29, 2010

Quick hit post

I'm pretty busy today, so I'm not going to talk long.  One thing I did learn today:  in php (and presumably other languages), when using the built in mcrypt library for 2 way encryption, the mcrypt_encrypt function returns a string with non-ascii characcters (i.e. - binary data).  This is a potential big problem when setting cookies, as it may produce unexpected results (i.e. - not freaking working).  The way to resolve this is:  base64_encode.  This method will take the binary string returned from mcrypt_encrypt and turn it into an ascii friendly string, which can be safely stored in a cookie.  When decrypting, simply run the string through base64_decode (before decrypting), and you will get the correct decryption.  Sweet!

No comments:

Post a Comment