Skip to content

Instantly share code, notes, and snippets.

@t3rmin4t0r
Created June 9, 2013 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t3rmin4t0r/5744974 to your computer and use it in GitHub Desktop.
Save t3rmin4t0r/5744974 to your computer and use it in GitHub Desktop.
RSA PEM simplified example
from Crypto.PublicKey import RSA
def genKey(bits=1024):
key = RSA.generate(2048)
f = open('rsa1024.pem','w')
f.write(key.exportKey('PEM'))
f.close()
return "rsa1024.pem"
pem = genKey(512)
key = RSA.importKey(open(pem,"r").read())
pubkey = key.publickey()
# TO generate ssh keys from these
# $ ssh-keygen -y -f rsa1024.pem >> ~/.ssh/authorized_keys
# and to test it, do
# $ ssh -i rsa1024.pem localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment