ez_crypto module

Inheritance diagram of ez_crypto

class ez_crypto.CryptoBaseClass[source]

Bases: object

Base class defining common functions.

attribute_setter(**kwargs)[source]

Sets kwargs as instance attributes.

return_dict(return_list)[source]

Extracts instance attributes into dictionary from return_list.

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.

hmac_digest(key, plaintext)[source]

Returns the hexdigest of a message, if provided with key.

hmac_verify(key, plaintext, hexmac_to_verify)[source]

Return bool. True if verification sucessfull, False otherwise.

remove_padding(text)[source]

Unpads decrypted text. Removes rightmost zeros and one (interrupt) byte.

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’]

decrypt_verify()[source]

Decrypt and unpack cipher block, check HMAC. Return HMAC check result in ‘authorized’ key, as well as the other plaintext attributes.

encrypt_sign()[source]

Pack content, exact time and sender to plaintext block. Sign and encrypt plaintext block. Return crypto items as dictionary.

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.

get_private_key(user)[source]

Import the senders keypair from Harddisk.

get_public_key(user)[source]

Get recipient public key from database.

priv_key_loc(user)[source]

Sets the path for the private keyfiles. Base path retrieved from the user preferences.

sign(private_key, plaintext)[source]

Sign plaintext with private key.

verify(public_key, plaintext, signature)[source]

Verify signature against plaintext with public key. Return True if successful, false otherwise.