This is a “Hazardous Materials” module. You should ONLY use it if you’re 100% absolutely sure that you know what you’re doing because this module is full of land mines, dragons, and dinosaurs with laser guns.


cryptography uses Abstract Base Classes as interfaces to describe the properties and methods of most primitive constructs. Backends may also use this information to influence their operation. Interfaces should also be used to document argument and return types.

Asymmetric interfaces

In 0.8 the asymmetric signature and verification interfaces were moved to the cryptography.hazmat.primitives.asymmetric module.

In 0.8 the asymmetric padding interface was moved to the cryptography.hazmat.primitives.asymmetric.padding module.


In 0.8 the DSA key interfaces were moved to the cryptography.hazmat.primitives.asymmetric.dsa module.


In 0.8 the RSA key interfaces were moved to the cryptography.hazmat.primitives.asymmetric.rsa module.

Elliptic Curve

In 0.8 the EC key interfaces were moved to the cryptography.hazmat.primitives.asymmetric.ec module.

Key derivation functions

In 0.8 the key derivation function interface was moved to the cryptography.hazmat.primitives.kdf module.

class cryptography.hazmat.primitives.interfaces.MACContext[source]

New in version 0.7.

Parameters:data (bytes) – The data you want to authenticate.
Returns:The message authentication code.
Returns:A MACContext that is a copy of the current context.
Parameters:signature (bytes) – The signature to verify.
Raises:cryptography.exceptions.InvalidSignature – This is raised when the provided signature does not match the expected signature.