Skip to content
This repository was archived by the owner on Apr 20, 2025. It is now read-only.

Commit 6defc80

Browse files
committed
Generate PublicKey from PrivateKey
1 parent 5b377fb commit 6defc80

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

rsa/key.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,18 @@ def blinded_encrypt(self, message: int) -> int:
499499
encrypted = rsa.core.encrypt_int(blinded, self.d, self.n)
500500
return self.unblind(encrypted, blindfac_inverse)
501501

502+
def public_key(self) -> PublicKey:
503+
"""Generates the corresponding PublicKey from the PrivateKey.
504+
505+
Equivalent to
506+
>>> pubkey = PublicKey(privkey.n, privkey.e)
507+
508+
:returns: the public key that belongs to the private key
509+
:rtype: PublicKey
510+
"""
511+
512+
return PublicKey(self.n, self.e)
513+
502514
@classmethod
503515
def _load_pkcs1_der(cls, keyfile: bytes) -> "PrivateKey":
504516
"""Loads a key in PKCS#1 DER format.

0 commit comments

Comments
 (0)