decrypt_asymmetric
decrypt_asymmetric
Functions
| Name | Description |
|---|---|
| decrypt_asymmetric | Decrypts a message using the receiver’s private key and verifies the |
decrypt_asymmetric
decrypt_asymmetric.decrypt_asymmetric(
encrypted_data,
receiver_private_key,
sender_public_key,
)Decrypts a message using the receiver’s private key and verifies the signature using the sender’s public key. This ensures both confidentiality (only receiver can decrypt) and authenticity (verifies sender identity).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| encrypted_data | str | Base64-encoded JSON containing encrypted message and signature. | required |
| receiver_private_key | bytes or str | The receiver’s RSA private key in PEM format (bytes) or path to key file (str). | required |
| sender_public_key | bytes or str | The sender’s RSA public key in PEM format (bytes) or path to key file (str) for signature verification. | required |
Returns
| Name | Type | Description |
|---|---|---|
| str | The decrypted and verified plaintext message. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If decryption fails, signature verification fails, or keys are invalid. |
Examples
>>> from imitation_game.generate_asymmetric_key import generate_asymmetric_key
>>> from imitation_game.encrypt_asymmetric import encrypt_asymmetric
>>> from imitation_game.decrypt_asymmetric import decrypt_asymmetric
>>> receiver_public, receiver_private = generate_asymmetric_key()
>>> sender_public, sender_private = generate_asymmetric_key()
>>> encrypted = encrypt_asymmetric(
... "Hello, world!",
... receiver_public,
... sender_private,
... )
>>> decrypt_asymmetric(encrypted, receiver_private, sender_public)
'Hello, world!'