print question - character representation

A

Ajay

hi!

i am calculating a digest of some data (using hmac) and printing it to a
cookie. the problem is the hash may contain special characters. when these
are printed they get converted to \<number> representation.
later when i receive the cookie i recalculate the hmac and do a comparison
which returns false because of the conversion when writing to a cookie

q - how do i stop the conversion from happening? if i cant then how can i
convert the hmac i recalculate on receiving the cookie to the same
representation as the one printed

thanks

cheers
 
B

Brian Gough

Ajay said:
i am calculating a digest of some data (using hmac) and printing it to a
cookie. the problem is the hash may contain special characters. when these
are printed they get converted to \<number> representation.
later when i receive the cookie i recalculate the hmac and do a comparison
which returns false because of the conversion when writing to a cookie
q - how do i stop the conversion from happening?

Use the hexdigest() method instead of digest() to avoid non-printable
characters. See the hmac library documentation for details.
 
M

Michael Foord

Ajay said:
hi!

i am calculating a digest of some data (using hmac) and printing it to a
cookie. the problem is the hash may contain special characters. when these
are printed they get converted to \<number> representation.
later when i receive the cookie i recalculate the hmac and do a comparison
which returns false because of the conversion when writing to a cookie

q - how do i stop the conversion from happening? if i cant then how can i
convert the hmac i recalculate on receiving the cookie to the same
representation as the one printed

thanks

cheers

One way is to use a binary to ascii conversion - like the binascii module.

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top