Created
February 10, 2011 18:11
-
-
Save formido/821003 to your computer and use it in GitHub Desktop.
python: base 64 encode the sha1 hash of a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import base64 | |
>>> import hashlib | |
>>> base64.b64encode(hashlib.sha1("test").digest()) | |
'qUqP5cyxm6YcTAhz05Hph5gvu9M=' |
thanks a lot!
nice, that's what I was looking for.
quick question, why does mine output
b'2jDkVwX3mqdVW1OOCY0KsoT7xsiQ+S7YrRcitjqmkgE='
what's the b part about?
The 'b' part is telling you your string is encoded as bytes. You have to decode it (again):
mystring.decode('utf-8') or whatever encoding
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was wondering how to use
hashlib.sha***()
with variables!!Thx a lot!