Skip to content

Commit

Permalink
Generate PublicKey from PrivateKey
Browse files Browse the repository at this point in the history
  • Loading branch information
bliepp committed Jan 9, 2022
1 parent 5b377fb commit 6defc80
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rsa/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,18 @@ def blinded_encrypt(self, message: int) -> int:
encrypted = rsa.core.encrypt_int(blinded, self.d, self.n)
return self.unblind(encrypted, blindfac_inverse)

def public_key(self) -> PublicKey:
"""Generates the corresponding PublicKey from the PrivateKey.
Equivalent to
>>> pubkey = PublicKey(privkey.n, privkey.e)
:returns: the public key that belongs to the private key
:rtype: PublicKey
"""

return PublicKey(self.n, self.e)

@classmethod
def _load_pkcs1_der(cls, keyfile: bytes) -> "PrivateKey":
"""Loads a key in PKCS#1 DER format.
Expand Down

0 comments on commit 6defc80

Please sign in to comment.