ez_crypto module¶
- exception ez_crypto.PrivateKeyError(value)[source]¶
Bases: exceptions.Exception
PrivateKeyError exception is raised if the private key is not found or corrupted.
- exception ez_crypto.PublicKeyError(value)[source]¶
Bases: exceptions.Exception
PublicKeyError exception is raised if the public key is not found or corrupted.
- class ez_crypto.eZ_AES(plaintext=None, **kwargs)[source]¶
Bases: ez_crypto.CryptoBaseClass
AES cipher object. Provides symmetric encryption. Requires plaintext string or ciphered dictionary object. Dictionary object must contain following keys: [‘iv’, ‘key’, ‘cipher’] Encryption parameters as of crypt_mode_1: keylength = 32 Bytes, padding = ‘...’, AES cipher mode = Cipher Block Chain.
- add_padding(text)[source]¶
Pads text to whole blocks (AES blocksize = 16). Padding scheme is binary ‘100000...’. If message length is multiple of blocksize, a whole additional block will be padded.
- decrypt()[source]¶
Produces plaintext from ciphertext, if provided with correct key and encryption parameters.
- encrypt()[source]¶
Creates random IV (Injection Vector) and random symmetric key. Encrypts padded text. Returns dictionary with base64 encoded ciphertext, key, IV and the crypt_mode used.
- class ez_crypto.eZ_CryptoScheme(**kwargs)[source]¶
Bases: ez_crypto.CryptoBaseClass
Outer crypto API to encrypt+sign and decrypt+verify message objects. Encryption must be provided as dictionary with following keys: [‘etime’, ‘sender’, ‘recipient’, ‘content’]
- class ez_crypto.eZ_RSA[source]¶
Bases: ez_crypto.CryptoBaseClass
RSA cipher object. Provides asymmetric encrytpion. Recommended minimal keylength: 2048 bit.
- RSA_KEY_SIZE = 2048¶
- decrypt(private_key, ciphertext)[source]¶
RSA decrypt method, PKCS1_OAEP. (See PyCrypto documentation for further information.)
- encrypt(public_key, plaintext)[source]¶
RSA encrypt method, PKCS1_OAEP. (See PyCrypto documentation for further information.)
- generate_keys(user, testing=False)[source]¶
Create RSA keypair, return the exported public key, which will be stored in the database, and write the exported private key to disc.