# Hmac

Creates an algorithmic hash of an object

## Method Signature

```
Hmac(input=[any], key=[any], algorithm=[string], encoding=[string], numIterations=[integer])
```

### Arguments

| Argument        | Type      | Required | Description                                                                    | Default   |
| --------------- | --------- | -------- | ------------------------------------------------------------------------------ | --------- |
| `input`         | `any`     | `true`   | The item to be hashed                                                          |           |
| `key`           | `any`     | `true`   |                                                                                |           |
| `algorithm`     | `string`  | `false`  | The supported {@link java.security.MessageDigest} algorithm (case-insensitive) | `HmacMD5` |
| `encoding`      | `string`  | `false`  | Applicable to strings ( default "utf-8" )                                      | `utf-8`   |
| `numIterations` | `integer` | `false`  |                                                                                | `1`       |

## Examples

### Example HMAC Using HMACSHA256

[Run Example](https://try.boxlang.io/?code=eJzLyE1M1lBQyi1OV9JRUCpOTS5KLQGxPHwdnYM9HI1MzZQUNK25AOHlCjM%3D)

```java
hmac( "msg", "secret", "HMACSHA256" );

```

Result: fe4f9c418f683f034f6af90d1dd5b86ac0355dd96332c59cc74598d0736107f6

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJytkctqAjEUhvfzFAdXDljM5DJJkC5yG9x01foAg6Y6dC52JlJ8%2B8betKBSipBN%2FpN8%2BT%2FS%2BGEo1x7uYRQ21QBxlRD8EEaz5MXvD7nSJsMk7qdTWAxVu4aw8dD7113V%2BxU8V75eDdC19T7p%2FbCrQ7w0f1BmDM0nfAIHUjpL3voqeLtrtmP4OpnOIFI5zzlHlCAjCedC2byQmaZEUUWQzuXvl7ttqLq2rKGs110kbhrYln3Z%2BOB7GM%2Bbcvk4V1maHMdR4juOGldKTk6YV%2FoiKh0jWjlCpKEKMSa45VprhQXjjAonCkMw%2F0dvzPLzzePgNt0ZIpLKHGFnHSmKPDOCFtQ4lhkpnVNYxkipjFLlHGO44DbDKP6JypHl9oKTb5fd6pCeKC2eijuRJj%2BjKPMR%2FdljcsReMEpuovQOuK%2FlKw%3D%3D)

```java
message = "this is a test";
key = "ABC123";
// Using the required fields only
result = HMAC( message, key );
writeDump( result ); // 776770430C93778AD6F91B43A4A30B69
// Using the optional algorithm parameter (HmacSHA1)
algorithm = "HmacSHA1";
result = HMAC( message, key, algorithm );
writeDump( result ); // 049E53BAE339C4A05587D7BBBA2857548E8FC327
// Using the optional algorithm parameter (HmacSHA256)
algorithm = "HmacSHA256";
result = HMAC( message, key, algorithm );
writeDump( result ); // 0503949602EDE3FF61C84F4CE51C99EEA2961CAA144AEE552F7D120AD6A60D7D
// Using the optional encoding parameter (UTF-8)
encoding = "UTF-8";
result = HMAC( message, key, algorithm, encoding );
writeDump( result );
 // 0503949602EDE3FF61C84F4CE51C99EEA2961CAA144AEE552F7D120AD6A60D7D

```

## Related

* [Decrypt](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/encryption/decrypt)
* [DecryptBinary](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/encryption/decryptbinary)
* [Encrypt](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/encryption/encrypt)
* [EncryptBinary](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/encryption/encryptbinary)
* [GeneratePBKDFKey](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/encryption/generatepbkdfkey)
* [GenerateSecretKey](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/encryption/generatesecretkey)
* [Hash](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/encryption/hash)
* [Hash40](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/encryption/hash40)
