Skip to content

Instantly share code, notes, and snippets.

@xtornasol512
Created October 3, 2017 23:44
Show Gist options
  • Save xtornasol512/6e5acfaabc32ecdaa8a35df172f717c8 to your computer and use it in GitHub Desktop.
Save xtornasol512/6e5acfaabc32ecdaa8a35df172f717c8 to your computer and use it in GitHub Desktop.
Convert any file to base64 using base64 python standard library
''' Convert any file to base64 using base64 python standard library '''
import base64
with open('MyFile.ext', 'rb') as f:
# read file as binary and encode to base64
encoded_string = base64.b64encode(f.read())
with open('cer.base64', 'w') as f:
# write in a new file the base64
f.write(encoded_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment