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>
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
int = 64Length 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
generate shared-secret = kdf( ecdhAgree(myPrivKey, msg[1:65]) )
verify tag
decrypt ecdhAgree(r, recipientPublic) == ecdhAgree(recipientPrivate, R) [where R = r*G, and recipientPublic = recipientPrivate*G]
Parameters:
data (
bytes) – Data to be decryptedprivate_key (
PrivateKey) – Private key to be used in agreement.shared_mac_data (
bytes) – shared mac additional data as suffix.
Return type:
bytesReturns: Decrypted byte string
Example:
encrypt(data, public_key, shared_mac_data=b'')
Encrypt data with ECIES method to the given public key
generate r = random value
generate shared-secret = kdf( ecdhAgree(r, P) )
generate R = rG [same op as generating a public key]
0x04 || R || AsymmetricEncrypt(shared-secret, plaintext) || tag
Parameters:
data (
bytes) – Data to be encryptedpublic_key (
PublicKey) – Public to be used to encrypt provided data.shared_mac_data (
bytes) – shared mac additional data as suffix.
Return type:
bytesReturns: Encrypted byte string
Example:
generate_private_key()
Generates a new SECP256K1 private key and return it
Return type:
PrivateKeyReturns: 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:
PublicKeyReturns: 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:
boolReturns: 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