---
title: HMAC
slug: aura/hmac
docTags: 
createdAt: 2025-07-07T20:39:55.891Z
---

Utilizado para gerar tokens HMAC com os algoritmos de criptografia SHA 256, SHA 512 ou SHA 1.

## Atalhos

- [SHA-512](#)
- [SHA-256](#)
- [SHA-1](#)

***

### Métodos

### New SHA 256

```lua
-- @param secret The secret used to create the HMAC.
-- @param input The input used to create the HMAC.
-- @return bytes that can be transformed into base64 on hex string to be used.
hmac["SHA256"].new(secret, input)
```

```lua
-- example usage:

local my_hmac = hmac["SHA256"].new("secret", "input")


local hmac_base64 = base64.encode(my_hmac)
-- jYmF0Et6vTLLqjd5o9qgGeDSaaIq7BWvjnKW9wLMaMY=

local hmac_hex = x:gsub(".", function(s)
    return string.format("%02x", string.byte(s))
end)
-- 8d8985d04b7abd32cbaa3779a3daa019e0d269a22aec15af8e7296f702cc68c6
```

### New SHA 512

```lua
-- @param secret The secret used to create the HMAC.
-- @param input The input used to create the HMAC.
-- @return bytes that can be transformed into base64 on hex string to be used.
hmac["SHA512"].new(secret, input)
```

```lua
-- example usage:

local my_hmac = hmac["SHA512"].new("secret", "input")


local hmac_base64 = base64.encode(my_hmac)
-- Ksle03F+BCxwZKX6fDGCMM022F4G+P+Dc9BMoX42Fingn0a38VH/OCo/SMWxkSFEbkXCWI8P8d6fdLBADa74Hw==

local hmac_hex = x:gsub(".", function(s)
    return string.format("%02x", string.byte(s))
end)
-- 2ac95ed3717e042c7064a5fa7c318230cd36d85e06f8ff8373d04ca17e361629e09f46b7f151ff382a3f48c5b19121446e45c2588f0ff1de9f74b0400daef81f
```

### New SHA 1

```lua
-- @param secret The secret used to create the HMAC.
-- @param input The input used to create the HMAC.
-- @return bytes that can be transformed into base64 on hex string to be used.
hmac["SHA1"].new(secret, input)
```

```lua
-- example usage:

local my_sha1_hmac = hmac["SHA1"].new("secret", "input")
```

