gdritter repos dogs / master bin / b64-payload
master

Tree @master (Download .tar.gz)

b64-payload @masterraw · history · blame

#!/usr/bin/env python3

import base64
import json
import sys

USAGE='''
{0} --key1=file1 --key2=file2 ...
'''

def main(args):
    result = {}
    for key, filename in args.items():
        with open(filename, 'rb') as f:
            contents = f.read()
        result[key] = base64.b64encode(contents).decode('utf-8')
    json.dump(result, sys.stdout)

if __name__ == '__main__':
    if '--help' in sys.argv[1:]:
        print(USAGE.format(sys.argv[0]))
        sys.exit(0)

    args = dict((arg.strip('--').split('=') for arg in sys.argv[1:]))
    main(args)