2020-07-07 00:58:43 -04:00
|
|
|
---
|
2023-10-20 03:42:39 -04:00
|
|
|
title: crypto.HMAC
|
2022-04-08 07:32:01 -04:00
|
|
|
description: Returns a cryptographic hash that uses a key to sign a message.
|
2023-12-04 09:14:18 -05:00
|
|
|
categories: []
|
2023-10-20 03:42:39 -04:00
|
|
|
keywords: []
|
2023-12-04 09:14:18 -05:00
|
|
|
action:
|
2023-10-20 03:42:39 -04:00
|
|
|
aliases: [hmac]
|
2023-12-04 09:14:18 -05:00
|
|
|
related:
|
|
|
|
- functions/crypto/FNV32a
|
|
|
|
- functions/crypto/MD5
|
|
|
|
- functions/crypto/SHA1
|
|
|
|
- functions/crypto/SHA256
|
2023-10-20 03:42:39 -04:00
|
|
|
returnType: string
|
|
|
|
signatures: ['crypto.HMAC HASH_TYPE KEY MESSAGE [ENCODING]']
|
|
|
|
aliases: [/functions/hmac]
|
2020-07-07 00:58:43 -04:00
|
|
|
---
|
|
|
|
|
2022-04-08 07:32:01 -04:00
|
|
|
Set the `HASH_TYPE` argument to `md5`, `sha1`, `sha256`, or `sha512`.
|
2020-07-07 00:58:43 -04:00
|
|
|
|
2022-04-08 07:32:01 -04:00
|
|
|
Set the optional `ENCODING` argument to either `hex` (default) or `binary`.
|
2020-07-07 00:58:43 -04:00
|
|
|
|
2022-04-08 07:32:01 -04:00
|
|
|
```go-html-template
|
|
|
|
{{ hmac "sha256" "Secret key" "Secret message" }}
|
|
|
|
5cceb491f45f8b154e20f3b0a30ed3a6ff3027d373f85c78ffe8983180b03c84
|
2020-07-07 00:58:43 -04:00
|
|
|
|
2022-04-08 07:32:01 -04:00
|
|
|
{{ hmac "sha256" "Secret key" "Secret message" "hex" }}
|
|
|
|
5cceb491f45f8b154e20f3b0a30ed3a6ff3027d373f85c78ffe8983180b03c84
|
|
|
|
|
|
|
|
{{ hmac "sha256" "Secret key" "Secret message" "binary" | base64Encode }}
|
|
|
|
XM60kfRfixVOIPOwow7Tpv8wJ9Nz+Fx4/+iYMYCwPIQ=
|
|
|
|
```
|