Skip to content

Instantly share code, notes, and snippets.

@cbscribe
Created February 2, 2022 15:57
Show Gist options
  • Save cbscribe/7aef87da687e6cb7c0c620b2887594f7 to your computer and use it in GitHub Desktop.
Save cbscribe/7aef87da687e6cb7c0c620b2887594f7 to your computer and use it in GitHub Desktop.
Create public/private RSA key pair
from Crypto.PublicKey import RSA
key_pair = RSA.generate(2048)
print("p: ", key_pair.p)
print("q: ", key_pair.q)
print("m: ", key_pair.n)
print("e: ", key_pair.e)
print("d: ", key_pair.d)
priv = key_pair.export_key()
pub = key_pair.publickey().export_key()
with open("private.key", "w") as f:
f.write(priv.decode())
with open("public.key", "w") as f:
f.write(pub.decode())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment