# (A) REQUIRED MODULES import base64 import ecdsa # (B) GENERATE KEYS # CREDITS : https://gist.github.com/cjies/cc014d55976db80f610cd94ccb2ab21e pri = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p) pub = pri.get_verifying_key() private = base64.urlsafe_b64encode(pri.to_string()).decode("utf-8").strip("="), public = base64.urlsafe_b64encode(b"\x04" + pub.to_string()).decode("utf-8").strip("=") import pathlib keydir = pathlib.Path('keys') keydir.mkdir(exist_ok=True) with open(keydir / 'public_key.txt', 'w') as fp: print(public, file=fp) with open(keydir / 'private_key.txt', 'w') as fp: print(private, file=fp)