# `encryption` module

The **`encryption` module** offers a set of high-level functions for data
protection and secure communication. It simplifies the process of encrypting and
decrypting strings using password-derived keys and provides specialized handling
for S/MIME email verification and decryption to ensure message integrity and
confidentiality.

### TIPCommon.encryption.decrypt

`TIPCommon.encryption.decrypt(enc_data: bytes, key: str) → str`

Decrypts data using a provided password.

#### Parameters

| Parameters ||
|---|---|
| `enc_data` | `bytes` The encrypted data to decrypt. |
| `key` | `str` The password used for key generation during the decryption process. |

#### Returns

The decrypted message.

#### Return type

`str`

### TIPCommon.encryption.decrypt_email

`TIPCommon.encryption.decrypt_email(smime_email_config: SmimeEmailConfig, logger: ScriptLogger) → Message`

Checks if an email message is encrypted or signed and performs the necessary
decryption or verification.

#### Parameters

| Parameters ||
|---|---|
| `smime_email_config` | `SmimeEmailConfig` A configuration object that contains the email message (`email.message.Message`), the base64-encoded private key, the certificate, and the CA certificate. |
| `logger` | `ScriptLogger` An instance of `ScriptLogger` that logs the decryption and verification process. |

#### Returns

A message object that contains the decrypted or verified content.

#### Return type

`email.message.Message`

### TIPCommon.encryption.encrypt

`TIPCommon.encryption.encrypt(data: str, key: str) → bytes`

Encrypts a JSON string using a provided key.

#### Parameters

| Parameters ||
|---|---|
| `data` | `str` The JSON string to encrypt. |
| `key` | `str` The password used for key generation during the encryption process. |

#### Returns

The encrypted message as a byte string.

#### Return type

`bytes`

### TIPCommon.encryption.get_private_key

`TIPCommon.encryption.get_private_key(password: str) → bytes`

Derives a cryptographic key from a provided password.

#### Parameters

| Parameters ||
|---|---|
| `password` | `str` The password string from which the private key is generated. |

#### Returns

A byte string that represents the derived private key.

#### Return type

`bytes`