import os, subprocess, sys, random, string, base64 def main(): s = ''.join([random.choice(string.ascii_letters) for _ in range(8)]) print(f"string generated: '{s}'") infile = "/tmp/infile" outfile = "/tmp/outfile" with open(infile, 'w+') as f: f.write(s) os.system(f"openssl dgst -sign key.pem -keyform PEM -sha256 -out {outfile} -binary {infile}") os.remove(infile) with open(outfile, 'rb') as f: sign = f.read() sign = base64.b64encode(sign).decode() print(f"key: SHTP-{s}-{sign}") os.remove(outfile) if __name__ == "__main__": main()