# Encryption module

### TIPCommon.encryption.decrypt

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

Decrypts data with the provided key.

#### Parameters

| Parameters ||
|---|---|
| `enc_data` | `bytes` The data to decrypt. |
| `key` | `str` The password used for key generation. |

#### 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 decrypts or verifies it.

#### Parameters

| Parameters ||
|---|---|
| `email` | `email.message.Message` An `email.message.Message` object containing email and certificate details. |
| `private_key_b64` | `str` A base64-encoded private key. |
| `certificate_b64` | `str` A base64-encoded certificate. |
| `ca_certificate_b64` | `str` A base64-encoded CA certificate. |
| `logger` | `ScriptLogger` A `ScriptLogger` instance. |

#### Returns

A Message object with a decrypted or verified message.

#### Return type

`email.message.Message`

### TIPCommon.encryption.encrypt

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

Encrypts data with the provided key.

#### Parameters

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

#### Returns

The encrypted message.

#### Return type

`bytes`

### TIPCommon.encryption.get_private_key

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

Derives a private key from a password.

#### Parameters

| Parameters ||
|---|---|
| `password` | `str` The password to generate the key from. |

#### Returns

A byte string.

#### Return type

`bytes`

**Need more help?** [Get answers from Community members and Google SecOps professionals.](https://security.googlecloudcommunity.com/)