# &adminguide;

## Overview

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

## 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:

- libgcrypt - part of GnuPG project (https://gnupg.org/software/libgcrypt/index.html).

## Parameters

### `init_vector` (str)

The initialization vector used for the cryptographic operations. This needs to be a string value with 16 bytes lengths.

Default value is set in the C code.

#### Set `init_vector` parameter

    ...
    modparam("gcrypt", "init_vector", "abcdefghijklmnop")
    ...

### `aes_mode` (int)

Set it to 1 in order to do AES CBC encryption mode. By default, it does AES ECB mode.

Default value is 0.

#### Set `aes_mode` parameter

    ...
    modparam("gcrypt", "aes_mode", 1)
    ...

### `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 libcrypt 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("gcrypt", "register_callid", 1)
    ...

## Functions

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

Encrypts the text with the key using AES256 ECB 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.

#### `gcrypt_aes_encrypt` usage

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

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

Decrypts the text with the key using AES256 ECB 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.

#### `gcrypt_aes_decrypt` usage

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