legacy_encryption

Legacy version of encryption module. Learn more about encryption.

exception human_protocol_sdk.legacy_encryption.DecryptionError

Bases: Exception

Raised when a message could not be decrypted.

class human_protocol_sdk.legacy_encryption.Encryption

Bases: object

Encryption class specialized in encrypting and decrypting a byte string.

CIPHER

Cipher algorithm definition.

alias of AES

ELLIPTIC_CURVE : EllipticCurve = <cryptography.hazmat.primitives.asymmetric.ec.SECP256K1 object>

Elliptic curve definition.

KEY_LEN = 32

ECIES using AES256 and HMAC-SHA-256-32

MODE

Cipher mode definition.

alias of CTR

PUBLIC_KEY_LEN : int = 64

Length of public keys: 512 bit keys in uncompressed form, without format byte

decrypt(data, private_key, shared_mac_data=b'')

Decrypt data with ECIES method using the given private key

  1. generate shared-secret = kdf( ecdhAgree(myPrivKey, msg[1:65]) )

  2. verify tag

  3. decrypt ecdhAgree(r, recipientPublic) == ecdhAgree(recipientPrivate, R) [where R = r*G, and recipientPublic = recipientPrivate*G]

  • Parameters:

    • data (bytes) – Data to be decrypted

    • private_key (PrivateKey) – Private key to be used in agreement.

    • shared_mac_data (bytes) – shared mac additional data as suffix.

  • Return type:bytes

  • Returns: Decrypted byte string

  • Example:

encrypt(data, public_key, shared_mac_data=b'')

Encrypt data with ECIES method to the given public key

  1. generate r = random value

  2. generate shared-secret = kdf( ecdhAgree(r, P) )

  3. generate R = rG [same op as generating a public key]

  4. 0x04 || R || AsymmetricEncrypt(shared-secret, plaintext) || tag

  • Parameters:

    • data (bytes) – Data to be encrypted

    • public_key (PublicKey) – Public to be used to encrypt provided data.

    • shared_mac_data (bytes) – shared mac additional data as suffix.

  • Return type:bytes

  • Returns: Encrypted byte string

  • Example:

generate_private_key()

Generates a new SECP256K1 private key and return it

  • Return type:PrivateKey

  • Returns: New SECP256K1 private key.

  • Example:

static generate_public_key(private_key)

Generates a public key with combination to private key provided.

  • Parameters:private_key (bytes) – Private to be used to create public key.

  • Return type:PublicKey

  • Returns: Public key object.

  • Example:

static is_encrypted(data)

Checks whether data is already encrypted by verifying ecies header.

  • Parameters:data (bytes) – Data to be checked.

  • Return type:bool

  • Returns: True if data is encrypted, False otherwise.

  • Example:

exception human_protocol_sdk.legacy_encryption.InvalidPublicKey

Bases: Exception

A custom exception raised when trying to convert bytes into an elliptic curve public key.

Last updated