Last active
December 22, 2015 19:28
-
-
Save lkdocs/6519387 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_RSA(bits=2048): | |
''' | |
Generate an RSA keypair with an exponent of 65537 in PEM format | |
param: bits The key length in bits | |
Return private key and public key | |
''' | |
from M2Crypto import RSA, BIO | |
new_key = RSA.gen_key(bits, 65537) | |
memory = BIO.MemoryBuffer() | |
new_key.save_key_bio(memory, cipher=None) | |
private_key = memory.getvalue() | |
new_key.save_pub_key_bio(memory) | |
return private_key, memory.getvalue() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment