470,591 Members | 2,005 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

Form sha1.hexdigest to sha1.digest

LMZ
How can convert string from sha1.hexdigest() to string that is the
same, like from sha1.digest()

thanks for your help!

Alexandr.
Apr 6 '08 #1
5 7850
How can convert string from sha1.hexdigest() to string that is the
same, like from sha1.digest()
Use binascii.unhexlify.

HTH,
Martin
Apr 6 '08 #2
Martin v. Löwis napisa³(a):
How can convert string from sha1.hexdigest() to string that is the
same, like from sha1.digest()

Use binascii.unhexlify.

HTH,
Martin
Or hexdigest_string.decode('hex')
Apr 6 '08 #3
Or hexdigest_string.decode('hex')

I would advise against this, as it's incompatible with Python 3.

Regards,
Martin
Apr 6 '08 #4
Martin v. Löwis napisa³(a):
Or hexdigest_string.decode('hex')

I would advise against this, as it's incompatible with Python 3.
I didn't know that, you actually made me look it up in the Python 3
FAQ. And yes, the difference is that decode will return bytes type
instead of a string. This may or may not be a problem (bytes type is
supposed to be immutable, so it can be used in many places where a
string is used now, ex. as a dict key).
Apr 6 '08 #5
>>Or hexdigest_string.decode('hex')
>I would advise against this, as it's incompatible with Python 3.

I didn't know that, you actually made me look it up in the Python 3
FAQ. And yes, the difference is that decode will return bytes type
instead of a string.
No. The decode method on string objects is removed, you can only
*encode* strings, but not decode them.
This may or may not be a problem
The problem is this:

pyhashlib.sha1(b"Hallo").hexdigest().decode("hex")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'

Regards,
Martin
Apr 6 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Michael Hamm | last post: by
1 post views Thread by Raghu | last post: by
4 posts views Thread by William Wisnieski | last post: by
2 posts views Thread by Rafal 'Raf256' Maj | last post: by
4 posts views Thread by ruben.de.visscher | last post: by
1 post views Thread by durumdara | last post: by
6 posts views Thread by LaundroMat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.