Last updated
Last updated
Legacy version of encryption module. Learn more about .
Bases: Exception
Raised when a message could not be decrypted.
Bases: object
Encryption class specialized in encrypting and decrypting a byte string.
Cipher algorithm defintion.
alias of AES
EllipticCurve
* = <cryptography.hazmat.primitives.asymmetric.ec.SECP256K1 object>Elliptic curve definition.
ECIES using AES256 and HMAC-SHA-256-32
Cipher mode definition.
alias of CTR
int
* = 64Length of public keys: 512 bit keys in uncompressed form, without format byte
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 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 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 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:
Generates a new SECP256K1 private key and return it
Return type: PrivateKey
Returns: New SECP256K1 private key.
Example:
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:
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:
Bases: Exception
A custom exception raised when trying to convert bytes into an elliptic curve public key.