Encryption Utils
Utility helpers for PGP encryption tasks.
EncryptionUtils ¶
Utility class providing static methods for PGP encryption operations.
This class offers helper methods for encrypting messages, verifying signatures, extracting signed data, and checking message encryption status without requiring a private key instance.
encrypt
staticmethod
¶
Encrypt a message using recipient public keys.
Encrypts a message so that only holders of the corresponding private keys can decrypt it. Does not sign the message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Plain text message to encrypt. |
required |
public_keys
|
List[str]
|
List of armored PGP public keys of the recipients. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Armored encrypted PGP message. |
Raises:
| Type | Description |
|---|---|
PGPError
|
If encryption fails or public keys are invalid. |
get_signed_data
staticmethod
¶
Extract the signed data from an armored signed message.
Retrieves the original message content from a PGP signed message without verifying the signature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Armored PGP signed message. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Extracted message content, or |
is_encrypted
staticmethod
¶
Check whether a message is armored and encrypted.
Determines if the provided text is a valid PGP encrypted message by checking the message header.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Text to check for encryption. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
verify
staticmethod
¶
Verify the signature of a message.
Checks if a signed message has a valid signature from the holder of the private key corresponding to the provided public key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Armored PGP message to verify. |
required |
public_key
|
str
|
Armored PGP public key to verify the signature against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|