write-ups-challenges-2022-2023/super-hightech-paint/super-hightech-paint-2/keys/generator.py
2022-11-24 22:59:22 +01:00

23 lines
614 B
Python

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()