human_protocol_sdk.encryption.encryption module

This class allows signing, verifying, encrypting, and decrypting messages at all levels of escrow processing.

The algorithm includes the implementation of the PGP encryption algorithm multi-public key encryption in Python. Using the vanilla ed25519 implementation Schnorr signatures for signature and curve25519 for encryption. Learn more.

Code Example

from human_protocol_sdk.encryption import Encryption

private_key = """-----BEGIN PGP PRIVATE KEY BLOCK-----

xVgEZJ1mYRYJKwYBBAHaRw8BAQdAGLLi15zjuVhD4eUOYR5v40kDyRb3nrkh
0tO5pPNXBIkAAQCXERVkGLDJadkZ3yzerGQeJyxM0Xl5IaEWrzQsSCt/mwz7
zRRIdW1hbiA8aHVtYW5AaG10LmFpPsKMBBAWCgA+BQJknWZhBAsJBwgJEAyX
rIbvfPxlAxUICgQWAAIBAhkBAhsDAh4BFiEEGWQNXhKpp2hxuxetDJeshu98
/GUAAFldAP4/HVRKEso+QiphYxfAIPbCbrZ+xy6RTFAW0tdjpDQwJQD+P81w
74pFhmBFjb8Aio87M1lLRzLSXjEVpKEciGerkQjHXQRknWZhEgorBgEEAZdV
AQUBAQdA+/XEHJiIC5GtJPxgybd2TyJe5kzTyh0+uzwAgD33R3cDAQgHAAD/
brJ3/2P+H4wOTV25YBp+UVvE0MqiVrCLk5kBNJdpN8AQn8J4BBgWCAAqBQJk
nWZhCRAMl6yG73z8ZQIbDBYhBBlkDV4SqadocbsXrQyXrIbvfPxlAAC04QD+
Jyyd/rDd4bEuAvsHFQHK2HMC2r0OLVHdMjygPELEA+sBANNtHfc60ts3++D7
dhjPN+xEYS1/BntokSSwC8mi56AJ
=GMlv
-----END PGP PRIVATE KEY BLOCK-----"""
passphrase = "passphrase"

encryption = Encryption(private_key, passphrase)

Module

class human_protocol_sdk.encryption.encryption.Encryption(private_key_armored, passphrase=None)

Bases: object

A class that provides encryption and decryption functionality using PGP (Pretty Good Privacy).

__init__(private_key_armored, passphrase=None)

Initializes an Encryption instance.

  • Parameters:

    • private_key_armored (str) – Armored representation of the private key

    • passphrase (Optional[str]) – Passphrase to unlock the private key. Defaults to None.

decrypt(message, public_key=None)

Decrypts a message using the private key.

  • Parameters:

    • message (str) – Armored message to decrypt

    • public_key (Optional[str]) – Armored public key used for signature verification. Defaults to None.

  • Return type: bytes

  • Returns: Decrypted message

  • Example:

sign(message)

Signs a message using the private key.

  • Parameters: message (Union[str, bytes]) – Message to sign

  • Return type: str

  • Returns: Armored and signed message

  • Example:

sign_and_encrypt(message, public_keys)

Signs and encrypts a message using the private key and recipient’s public keys.

  • Parameters:

    • message (Union[str, bytes]) – Message to sign and encrypt

    • public_keys (List[str]) – List of armored public keys of the recipients

  • Return type: str

  • Returns: Armored and signed/encrypted message

  • Example:

Last updated