telegram-oauth/gen_keys.py
2024-01-14 16:04:25 +08:00

27 lines
671 B
Python

from pathlib import Path
data_path = Path("data")
data_path.mkdir(exist_ok=True)
private_key_path = data_path / "private_key"
public_key_path = data_path / "public_key"
def gen_keys():
from Crypto.PublicKey import RSA
key = RSA.generate(2048)
private_key = key.export_key().decode("utf-8")
public_key = key.publickey().export_key().decode("utf-8")
if private_key_path.is_file() and public_key_path.is_file():
print("Keys already exist")
return
with open(private_key_path, "w") as f:
f.write(private_key)
with open(public_key_path, "w") as f:
f.write(public_key)
if __name__ == "__main__":
gen_keys()