Skip to content

Instantly share code, notes, and snippets.

@formido
Created February 10, 2011 18:11
Show Gist options
  • Save formido/821003 to your computer and use it in GitHub Desktop.
Save formido/821003 to your computer and use it in GitHub Desktop.
python: base 64 encode the sha1 hash of a string
>>> import base64
>>> import hashlib
>>> base64.b64encode(hashlib.sha1("test").digest())
'qUqP5cyxm6YcTAhz05Hph5gvu9M='
@ignazioc
Copy link

nice, that's what I was looking for.

@Yulovery
Copy link

quick question, why does mine output
b'2jDkVwX3mqdVW1OOCY0KsoT7xsiQ+S7YrRcitjqmkgE='

what's the b part about?

@dstieglitz
Copy link

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