Search code examples
pythonopensslcryptographypyopensslpython-cryptography

How do I access the components of a private RSA key in Python's cryptography module?


I'm not finding an API, but because it seems to delegate to OpenSSL, perhaps I'm not understanding how this works.

What I'm looking for is the equivalent of the first answer to this [1] but from within Python, using an RSA keypair that has just been generated and, for security reasons, has never been written to disk.

[1] How do I extract the private key components $N$ and $D$ from a private RSA key?


Solution

  • You want to call private_numbers on your RSAPrivateKey object. This will return an RSAPrivateNumbers object that has integer forms of the key components.