# HMAC\_MD5

**The HMAC\_MD5 function takes two Strings as input, a base string and a key, and returns the hash of the base string as a Hex- or Base64-encoded string, arrived at via the HMAC-MD5 algorithm.**

This function requires two [Strings](../../variable-data-types/the-text-variable-data-type) as input: a base string and key. As an option, it also accepts another string that defines if Hex or Base64 encoding will to be used to calculate the output: a string that gives the hash of the first input, as calculated by the [HMAC](https://en.wikipedia.org/wiki/HMAC)-[MD5 algorithm](https://en.wikipedia.org/wiki/MD5).&#x20;

#### Declaration

```javascript
HMAC_MD5(base_string, key, encode) -> hash
```

#### Parameters

**base\_string** (required, type:_string_) Any string.

**key** (required, type:_string_) The key used in the calculation of the HMAC.

**encode** (optional, type:_string_, default: "Hex")

The string "Hex" or "Base64". This defines if the hash of the base string will be Hex- or Base64-encoded, respectively.

If no value is given for **encode**, HMAC\_MD5 will return the Hex-encoded hash. If a value other than "Hex" or "Base64" is given for **encode**, HMAC\_MD5 will throw an error.

#### Return Values

**hash**(type: _string_) The hash of the input as calculated by the [HMAC](https://en.wikipedia.org/wiki/HMAC)-[MD5 algorithm](https://en.wikipedia.org/wiki/MD5).

#### Examples

The following example uses the key "111" to calculate Hex-encoded hash of the string "This is a string." according to the HMAC-MD5 algorithm:

```javascript
HMAC_MD5("This is a string.", "111") => "8884c1b44e9d3ffa77488052a4aed804"
```

The following example also uses the key "111" to return the Hex-encoded hash of the string "This is a string." as calculated by the HMAC-MD5 algorithm. Note that it returns the same output as the above example; there is no difference in output between explicitly defining "Hex" as the value for **encode** and not defining **encode** at all:

```javascript
HMAC_MD5("This is a string.", "111", "Hex") => "8884c1b44e9d3ffa77488052a4aed804"
```

The following example uses the key "111" to calculate Base64-encoded hash of the string "This is a string." according to the HMAC-MD5 algorithm. Note how this differs from the first two examples:

```javascript
HMAC_MD5("This is a string.", "111", "Base64") => "E1YrRxGCMRtu6o0kEQPo8A=="
```

The following example uses the key "ai4nga0" to calculate Hex-encoded hash of the string "This is a string." according to the HMAC-MD5 algorithm. Note how the output is impacted by the key:

```javascript
HMAC_MD5("This is a string.", "ai4nga0") => "0edb9ad5d485a34c59b26da0c564ea8c"
```
