[HELP] a encode function with decode key in GO and PHP

575 views
Skip to first unread message

nvcnvn

unread,
May 13, 2011, 9:52:21 PM5/13/11
to golang-nuts
This may quite simple with some of you, but not so simple for me.

What I need is a encode function with the decode key can use on both
GO and PHP.

For example the GO web program set the encoded cookies. and the PHP
program (in the sub-domain) read the encoded cookies and decode it.

I hope that some one can help me! Because no way I can do this!

Kyle Lemons

unread,
May 14, 2011, 11:58:55 PM5/14/11
to nvcnvn, golang-nuts
Do you mean "encrypt" or "encode"?  The answer for both is structured the same, but the specifics are different.

Encodings:
Check out base64-encoding, which works brilliantly on both Go and PHP.

Encryption:
Check out AES-256-CBC, which should be supported by both.  Just make sure to bake in the IV you use and keep the key secret (stored on the server) or something.  If you don't want to do the padding/depadding yourself you could use OFB, which should also be supported by both.
http://www.php.net/manual/en/ref.mcrypt.php (MCRYPT_RIJNDAEL_256 and MCRYPT_MODE_CBC)

Another option you have is to store the data that you want to save in a database (both PHP and Go have MySQL bindings available) and then you don't have to encrypt/decrypt or encode/decode anything, you just give the user a special key that points into the database (and use some smarts to make sure it's the same IP/UserAgent/etc that's giving you the key).

HTH,
--
~Kyle

"Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" 
— Brian Kernighan

nvcnvn

unread,
May 15, 2011, 5:31:43 AM5/15/11
to golang-nuts
Thanks you very very much!
Thanks for your help about Encoding and Encryption, but
You just show me the other better way!
Reply all
Reply to author
Forward
0 new messages