Skip to content

Instantly share code, notes, and snippets.

@mikegrima
Created June 22, 2016 19:19
Show Gist options
  • Save mikegrima/66fbef16b7e1a11b58fe7731ccb196db to your computer and use it in GitHub Desktop.
Save mikegrima/66fbef16b7e1a11b58fe7731ccb196db to your computer and use it in GitHub Desktop.
Base64 Encoding and Decoding to Strings in Python.
import base64
# Convert this to a b64 string:
some_str = "Some string..."
b64string = base64.b64encode(some_str.encode("utf-8")).decode("utf-8")
# ^^ Without this, it's a byte array.
# /nomorehairpulling
print(b64string)
# And to decode:
back_to_some_str = base64.b64decode(b64string).decode("utf-8")
print(back_to_some_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment