CryptographicFields.cryptography module

exception CryptographicFields.cryptography.LengthError(length)[source]

Bases: Exception

CryptographicFields.cryptography.get_key(settings) → str[source]

Gets the encryption for encrypting & decrypting data.

Gets value from CRYPTOGRAPHIC_KEY & if not defined then from SECRET_KEY Checks the len of the key id less than 50 then raise LengthError

Raises

LengthError – It raises when the len of Encryption is less than 50 chars

Returns

Key for cryptography

Return type

str

CryptographicFields.cryptography.type_check(string) → bytearray[source]

Checks weather the inputed data is in correct format which is required for encryption & decryption.

Checks weather the inputed data is in correct format which is required for encryption & decryption. Which is in this case is bytearray

Parameters

string (Any) – Data from User

Returns

bytes

Return type

bytearray

CryptographicFields.cryptography.to_hex(string) → hex[source]

Converts bytes to hex

Converts the bytes received after encryption to hex for storing it in database

Parameters

string (bytes) – encrypted bytes

Returns

hexify the bytes

Return type

hex

CryptographicFields.cryptography.from_hex(hexstring) → bytearray[source]

converts hex to bytearray

Converts the hex string received from databse to bytes for decryption

Parameters

hexstring (hex) – hex string recieved from database

Returns

bytes from hex string

Return type

bytearray

CryptographicFields.cryptography.encrypt(string) → hex[source]

Encrypts the data

Encrypts the data recieved from user using AES-256 CFB

Parameters

string (Any) – Data from User

Returns

the hex of the encrypted string

Return type

hex

CryptographicFields.cryptography.decrypt(hexstring) → bytearray[source]

Decrypts the data

Decrypts the data recieved from database using AES-256 CFB

Parameters

hexstring (hex) – hex string recieved from database

Returns

bytes of decrypted string

Return type

bytearray