# &adminguide;

## Overview

This module provides various cryptography tools for use in &kamailio; configuration file.

It relies on OpenSSL libraries for cryptographic operations (libssl, libcrypto).

## Dependencies

### &kamailio; Modules

The following modules must be loaded before this module:

- none.

### External Libraries or Applications

The following libraries or applications must be installed before running &kamailio; with this module loaded:

- libcrypto - part of OpenSSL project

## Parameters

### `salt` (str)

A keyword to generate salt for encryption. It must be at least 8 chars long. If set to empty, no salt is used for encryption.

The salt is a binary array that is appended to the encryption password for better protection against dictionary attacks. Same salt and password need to be when encrypting and decrypting.

Default value is "..." (see code).

#### Set `salt` parameter

    ...
    modparam("crypto", "salt", "l0Bh2M8a")
    ...

### `register_callid` (int)

Set it to 1 in order to register a callback to core for generation of callid values for requests generated by &kamailio; tm module.

This callid generator uses libssl random and hashing functions for generating RFC 4122 version 4 UUID with high quality entropy. It is useful when wanting to have new callids that cannot be predicted from previous values.

Default value is 0.

#### Set `register_callid` parameter

    ...
    modparam("crypto", "register_callid", 1)
    ...

## Functions

### `crypto_aes_encrypt(text, key, res)`

Encrypts the text with the key using AES encryption algorithm. The result is encoded in base64 format and stored in res. The parameter res must be a read-write variables. The parameters text and key can be static strings or strings with variables (dynamic strings).

This function can be used from ANY_ROUTE.

#### `crypto_aes_encrypt` usage

    ...
    crypto_aes_encrypt("$rb", "my-secret-key", "$var(encrypted)");
    ...

### `crypto_aes_decrypt(text, key, res)`

Decrypts the text with the key using AES encryption algorithm. The text has to be encoded in base64 format. The parameter res must be a read-write variables. The parameters text and key can be static strings or strings with variables (dynamic strings).

This function can be used from ANY_ROUTE.

#### `crypto_aes_decrypt` usage

    ...
    crypto_aes_decrypt("$var(encrypted)", "my-secret-key", "$var(text)");
    ...