Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Encrypt to alphanumeric string and Decrypt to original string for use in URL

Tags:

php

encryption

What would be the best way to encode a json array into an alphanumeric string which can be used in a URL querystring?

I need something that is simple, yet not easy to crack. I've read through all the encrypt and decrypt documentation.

I need to encrypt a json array Eg: {"firstName":"John","lastName":"Doe"} to something like a14iw58swd33s541dg2k58kv3s4gvkjsdf33s9f3, so it can be used in a url query string like http://www.example.com/?v=a14iw58swd33s541dg2k58kv3s4gvkjsdf33s9f3.

I'll later decrypt this server side. Since it part of a URL, I cannot have something like ȃZ Vì§n‹ØfjÒ šçæ¹ä¯

What would be an easy and safe way to do this?

like image 460
Norman Avatar asked Apr 29 '13 05:04

Norman


1 Answers

  1. Encrypt using any encryption function you see fit, which will produce binary data.
  2. Run binary data through base64_encode to get an ASCII-only string.
  3. ???
  4. Profit!
  5. Reverse the above steps.
like image 193
deceze Avatar answered Sep 23 '22 05:09

deceze