encommon.crypts package#
Submodules#
encommon.crypts.crypts module#
- class encommon.crypts.crypts.Crypts(params: CryptsParams | None = None)[source]#
Bases:
objectEncrypt 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.
encommon.crypts.hashes module#
- class encommon.crypts.hashes.Hashes(string: str)[source]#
Bases:
objectCreate 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.
encommon.crypts.params module#
- class encommon.crypts.params.CryptParams[source]#
Bases:
BaseModelProcess and validate the core configuration parameters.
- class encommon.crypts.params.CryptsParams[source]#
Bases:
BaseModelProcess and validate the core configuration parameters.
Fields# Field
Type
Required
Default
Constraints
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:
objectEncrypt 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.
- class encommon.crypts.CryptsParams[source]#
Bases:
BaseModelProcess and validate the core configuration parameters.
Fields# Field
Type
Required
Default
Constraints
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:
objectCreate 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.