Created
June 22, 2016 19:19
-
-
Save mikegrima/66fbef16b7e1a11b58fe7731ccb196db to your computer and use it in GitHub Desktop.
Base64 Encoding and Decoding to Strings in Python.
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 | |
# 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