def newKey(e, n, d=None, p=None, q=None): """Create a new key.""" key = RSA.RSAobj() # Create a new empty RSA Key key.e, key.n = e, n # Feed it the ee and modulus if d is not None: key.d, key.p, key.q = d, p, q return key else: return key.publickey() # Return the public key variant