From 98f5e47dd852d8038364404c7ee5f183818584c8 Mon Sep 17 00:00:00 2001 From: SouthFox Date: Wed, 12 Jul 2023 00:12:00 +0800 Subject: [PATCH] [feat] gen key script --- misc.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 misc.py diff --git a/misc.py b/misc.py new file mode 100644 index 0000000..295d1c7 --- /dev/null +++ b/misc.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +"""Something misc.""" +import click +import sys + +from Crypto.PublicKey import RSA +from demo import config + + +@click.command() +def gen_key(): + """Generate key.""" + if config.KEY_PATH.exists(): + print("Key is existing!") + sys.exit(2) + else: + k = RSA.generate(2048) + privkey_pem = k.exportKey("PEM").decode("utf-8") + config.KEY_PATH.write_text(privkey_pem) + print("Done!") + + +if __name__ == "__main__": + gen_key()