Encrypting cookies in HTTP-headers
Thomas Weholt
2002 at weholt.org
Sun Dec 29 17:37:50 EST 2002
I need to do simple, or advanced if possible :-), encryption of cookies in
HTTP-requests. I've tried to use base64 and rotor but the cookies seem
scrambled when decoded. Does anybody has any example on how to achieve this
?
My code is something like this, using BaseHTTPServer :
# Setting the cookie :
key = base64.encodestring(key)
value = base64.encodestring(value)
self.send_header('Set-Cookie', '%s=%s' % (key, value))
# Reading it back :
import Cookie
c = Cookie.SmartCookie()
c.load(self.headers['Cookie'])
for key in c.data.keys()
d = c[key]
print base64.decode(d.key), base64.decode(d.value)
And the contents of the two fields are just crap.
If I get this to work I'll apply some encryption to the values first before
base64.encoding them. I tried to use rotor on the values without
base64-encoding, but the result contained characters that screwed up the
cookie completly, -- therefore base64 after encryption.
Any help appreciated.
Best regards,
Thomas Weholt
More information about the Python-list
mailing list