Skip to content

Instantly share code, notes, and snippets.

@samredai
Created December 11, 2018 02:10
Show Gist options
  • Save samredai/9ee1ce5c0ca81f6f3659ada12636a9ee to your computer and use it in GitHub Desktop.
Save samredai/9ee1ce5c0ca81f6f3659ada12636a9ee to your computer and use it in GitHub Desktop.
Python: Encode a string into bytes using base64, then decode it and convert it back to a string
import base64
base64.b64encode(b'Encode this string.')
#b'RW5jb2RlIHRoaXMgc3RyaW5nLg=='
decodedBytes = base64.b64decode(b'RW5jb2RlIHRoaXMgc3RyaW5nLg==')
print(decodedBytes)
#b'Encode this string.'
decodedString = decodedBytes.decode('utf-8')
print(decodedString)
#Encode this string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment