422,764 Members | 1,289 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,764 IT Pros & Developers. It's quick & easy.

Form sha1.hexdigest to sha1.digest

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
Or hexdigest_string.decode('hex')

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

Regards,
Martin
Apr 6 '08 #4

P: n/a
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

P: n/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.
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.