0

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?

Johannes Ernst
  • 3,072
  • 3
  • 42
  • 56

1 Answers1

2

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

Paul Kehrer
  • 13,466
  • 4
  • 40
  • 57
  • What about the other way around? If I have those private numbers, how can I reconstitute the PrivateKey object? (This API sure is trying hard to keep people from touching hazardous material ...) – Johannes Ernst Feb 18 '19 at 03:11
  • You can build an RSAPrivateNumbers object and then call `private_key` on it to convert it to a key object that can perform cryptographic operations. – Paul Kehrer Feb 20 '19 at 02:06
  • @JohannesErnst that's because the writers are security conscious, and most implementation vulnerabilitys are because of id10t user errors. – Legorooj Oct 13 '19 at 11:17