Skip to content

Instantly share code, notes, and snippets.

@ochaloup
Last active May 22, 2023 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochaloup/b3c2c2410f63782b75abcda96d261fea to your computer and use it in GitHub Desktop.
Save ochaloup/b3c2c2410f63782b75abcda96d261fea to your computer and use it in GitHub Desktop.
Python script to convert base64 formatted string to uint8 binary data array
#!~/.pyenv/shims/python3
# Usage:
# frombase64.py o9lBUTXmHRwGAAAAaGVsbG8z
# Output:
# [163,217,65,81,53,230,29,28,6,0,0,0,104,101,108,108,111,51]
import base64
import sys
if len(sys.argv) != 2:
print(f"Expecting argument of base64 string, not provided. Arguments: {sys.argv}")
exit(1)
string_key = sys.argv[1]
byte_array = base64.b64decode(string_key)
json_string = "[" + ",".join(map(lambda b: str(b), byte_array)) + "]"
print(json_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment