encommon.crypts package#

Submodules#

encommon.crypts.crypts module#

class encommon.crypts.crypts.Crypts(params: CryptsParams | None = None)[source]#

Bases: object

Encrypt and decrypt values using passphrase dictionary.

Example#

>>> phrase = Crypts.keygen()
>>> source = {'default': {'phrase': phrase}}
>>> params = CryptsParams(phrases=source)
>>> crypts = Crypts(params)
>>> encrypt = crypts.encrypt('example')
>>> encrypt
'$ENCRYPT;1.0;default;...
>>> crypts.decrypt(encrypt)
'example'
param params:

Parameters used to instantiate the class.

property params: CryptsParams#

Return the Pydantic model containing the configuration.

Returns:

Pydantic model containing the configuration.

encrypt(value: str, unique: str = 'default') str[source]#

Encrypt the provided value with the relevant passphrase.

Parameters:
  • value – String value that will returned encrypted.

  • unique – Unique identifier of mapping passphrase.

Returns:

Encrypted value using the relevant passphrase.

decrypt(value: str) str[source]#

Decrypt the provided value with the relevant passphrase.

Parameters:

value – String value that will returned decrypted.

Returns:

Decrypted value using the relevant passphrase.

create(unique: str, params: CryptParams) None[source]#

Create a new phrase using the provided input parameters.

Parameters:
  • unique – Unique identifier of mapping passphrase.

  • params – Parameters used to instantiate the class.

delete(unique: str) None[source]#

Delete the phrase from the internal dictionary reference.

Parameters:

unique – Unique identifier of mapping passphrase.

classmethod keygen() str[source]#

Return new randomly generated Fernet key for passphrase.

Returns:

Randomly generated Fernet key for passphrase.

encommon.crypts.crypts.crypt_clean(value: str) str[source]#

Return the parsed and normalized encrypted string value.

Parameters:

value – String value that will returned decrypted.

Returns:

Parsed and normalized encrypted string value.

encommon.crypts.hashes module#

class encommon.crypts.hashes.Hashes(string: str)[source]#

Bases: object

Create hash values using the provided at instantiation.

Example#

>>> hashes = Hashes('string')
>>> hashes.sha256
'473287f8298dba7163a897908958f7c0ea...

Example#

>>> hashes = Hashes('string')
>>> hashes.uuid
'38ffd1ed-2b4d-3c84-ae45-bf3bf354eee4'
param string:

String which will be used within hashing.

property string: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property md5: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha1: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha256: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha512: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property uuid: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property apache: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

encommon.crypts.params module#

class encommon.crypts.params.CryptParams[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Fields#

Field

Type

Required

Default

Constraints

phrase

str

Yes

min_length=1

phrase: Annotated[str, FieldInfo(annotation=NoneType, required=True, description='Passphrase for the operations', metadata=[MinLen(min_length=1)])]#
class encommon.crypts.params.CryptsParams[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Fields#

Field

Type

Required

Default

Constraints

phrases

dict[str, CryptParams]

Yes

min_length=0

phrases: Annotated[dict[str, CryptParams], FieldInfo(annotation=NoneType, required=True, description='Passphrases for the operations', metadata=[MinLen(min_length=0)])]#

Module contents#

class encommon.crypts.Crypts(params: CryptsParams | None = None)[source]#

Bases: object

Encrypt and decrypt values using passphrase dictionary.

Example#

>>> phrase = Crypts.keygen()
>>> source = {'default': {'phrase': phrase}}
>>> params = CryptsParams(phrases=source)
>>> crypts = Crypts(params)
>>> encrypt = crypts.encrypt('example')
>>> encrypt
'$ENCRYPT;1.0;default;...
>>> crypts.decrypt(encrypt)
'example'
param params:

Parameters used to instantiate the class.

property params: CryptsParams#

Return the Pydantic model containing the configuration.

Returns:

Pydantic model containing the configuration.

encrypt(value: str, unique: str = 'default') str[source]#

Encrypt the provided value with the relevant passphrase.

Parameters:
  • value – String value that will returned encrypted.

  • unique – Unique identifier of mapping passphrase.

Returns:

Encrypted value using the relevant passphrase.

decrypt(value: str) str[source]#

Decrypt the provided value with the relevant passphrase.

Parameters:

value – String value that will returned decrypted.

Returns:

Decrypted value using the relevant passphrase.

create(unique: str, params: CryptParams) None[source]#

Create a new phrase using the provided input parameters.

Parameters:
  • unique – Unique identifier of mapping passphrase.

  • params – Parameters used to instantiate the class.

delete(unique: str) None[source]#

Delete the phrase from the internal dictionary reference.

Parameters:

unique – Unique identifier of mapping passphrase.

classmethod keygen() str[source]#

Return new randomly generated Fernet key for passphrase.

Returns:

Randomly generated Fernet key for passphrase.

class encommon.crypts.CryptsParams[source]#

Bases: BaseModel

Process and validate the core configuration parameters.

Fields#

Field

Type

Required

Default

Constraints

phrases

dict[str, CryptParams]

Yes

min_length=0

phrases: Annotated[dict[str, CryptParams], FieldInfo(annotation=NoneType, required=True, description='Passphrases for the operations', metadata=[MinLen(min_length=0)])]#
class encommon.crypts.Hashes(string: str)[source]#

Bases: object

Create hash values using the provided at instantiation.

Example#

>>> hashes = Hashes('string')
>>> hashes.sha256
'473287f8298dba7163a897908958f7c0ea...

Example#

>>> hashes = Hashes('string')
>>> hashes.uuid
'38ffd1ed-2b4d-3c84-ae45-bf3bf354eee4'
param string:

String which will be used within hashing.

property string: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property md5: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha1: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha256: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property sha512: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property uuid: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.

property apache: str#

Return the value for the attribute from class instance.

Returns:

Value for the attribute from class instance.