Hash.SHA256.HMAC
----------------

Returns the a SHA256 HMAC based on the key and the data string.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Hash](component_Hash.md) | [3.1](newinversion31.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Hash.SHA256.HMAC"; Key; Data { ; Flags } ) 

**MBS**( **"Hash.SHA256.HMAC";** /\* Returns the a SHA256 HMAC based on the key and the data string. \*/  
**$Key**; /\* The key text to use.e.g. "Hello" \*/   
**$Data**; /\* The data text to use.e.g. "World" \*/   
**$Flags**) /\* Optional; Various flags you can combine by addition.  
Pass 1 for getting result Base64 encoded instead of Hex encoded.  
Pass 2 if key is Hex encoded and plugin should decode it first.  
Pass 4 if data is hex encoded and plugin should decode it first.  
Pass 8 for base64URL encoding. (new in v10.3)e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| Key | The key text to use. | "Hello" |  |
| Data | The data text to use. | "World" |  |
| Flags | Various flags you can combine by addition.   Pass 1 for getting result Base64 encoded instead of Hex encoded.   Pass 2 if key is Hex encoded and plugin should decode it first.   Pass 4 if data is hex encoded and plugin should decode it first.   Pass 8 for base64URL encoding. (new in v10.3) | 0 | Optional |

### Result

Returns the hash string.

### Description

Returns the a SHA256 HMAC based on the key and the data string.  
Keyed-Hash Message Authentication Code is a way to add salt to a hash for more security.  
By default we return the hash as hex encoded string.  
  
Please be aware that text can result in different hashes if it contains line endings. You may want to make sure that line endings are right with the [Text.ReplaceNewLine](TextReplaceNewLine.md) function before you compare hashes to results in other development tools. FileMaker uses Mac line endings by default and most examples for Javascript use Unix line endings.  
  
Can be used to sign requests for Amazon MWS.  
### Examples

Hash empty string

 MBS ( "Hash.SHA256.HMAC"; ""; "" )  
<small>  
Example result: B613679A0814D9EC772F95D778C35FC5FF1697C493715653C6C712144292C5AD</small>Hash a test string

 MBS ( "Hash.SHA256.HMAC"; "key"; "The quick brown fox jumps over the lazy dog")  
<small>  
Example result: F7BC83F430538424B13298E6AA6FB143EF4D59A14946175997479DBC2D1A3CD8</small>Hash with flags:

 MBS ( "Hash.SHA256.HMAC"; "6B6579"; "54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F67"; 2+4)  
<small>  
Example result: F7BC83F430538424B13298E6AA6FB143EF4D59A14946175997479DBC2D1A3CD8</small>FileMaker 16 vs. Plugin:

 # MBS Plugin:   
Set Variable \[ $r1 ; Value: MBS ( "[Hash.SHA512.HMAC](HashSHA512HMAC.md)"; "Key"; "Data") \]  
\# Same via FileMaker 16 native:   
Set Variable \[ $r2 ; Value: HexEncode( CryptAuthCode ( "Data" ; "SHA512" ; "Key" )) \]  
Calculate Amazon AWS Signature for canonical query:

 Set Variable \[ $Verb ; Value: "POST" \]   
Set Variable \[ $Domain ; Value: "mws.amazonservices.com" \]   
Set Variable \[ $Path ; Value: "/Orders/2013-09-01" \]   
Set Variable \[ $QueryString ; Value: "AWSAccessKeyId=AKIAJVZ5JFVD2SERTQIA&amp;Action=GetOrder&amp;AmazonOrderId.Id.1 =112-4707920-3733828&amp;SellerId=A1DGCWQ1HE6UN1&amp;SignatureMethod=HmacSHA256&amp;SignatureVersion=2&amp;Timestamp=2018-01-24T22%3A34%3A24Z&amp;Version=2013-09-01" \]   
Set Variable \[ $SecretKey ; Value: "1234567890" \]   
Set Variable \[ $Signature ; Value: MBS ( "Hash.SHA256.HMAC"; $SecretKey ; $Verb &amp; Char(10) &amp; $Domain &amp; Char(10) &amp; $Path &amp; Char(10) &amp; $QueryString ; 1 ) \]   
Show Custom Dialog \[ "AWS Signature" ; $signature \]  
<small>  
Example result: “hTX0IGOH+lWyaqZBf513TcB6Mk3U/hidyQvJASsn7aE="</small>Calculate a JSON Web Token (JWT) in FileMaker:

 Let ( \[  
  
// Header: {\\"alg\\":\\"HS256\\",\\"typ\\":\\"JWT\\"}  
// Payload: {"iss":"scotch.io","exp":1300819380,"name":"Chris Sevilleja","admin":true}  
  
// expected result: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dnZWRJbkFzIjoiYWRtaW4iLCJpYXQiOjE0MjI3Nzk2Mzh9.gzSraSYS8EXBxLN\_oWnFSRgCzcmJmMjLiuyu5CSpyHI  
  
secret = "secretkey";  
header = "{\\"alg\\":\\"HS256\\",\\"typ\\":\\"JWT\\"}";  
payload = "{\\"loggedInAs\\":\\"admin\\",\\"iat\\":1422779638}";  
encodedString = MBS ( "[Text.EncodeToBase64URL](TextEncodeToBase64URL.md)"; header; "UTF-8") &amp; "." &amp; MBS ( "[Text.EncodeToBase64URL](TextEncodeToBase64URL.md)"; payload; "UTF-8");  
// calculate hash  
hash = MBS ( "Hash.SHA256.HMAC"; secret; encodedString; 1+8 );  
// and built final result:  
result = encodedString &amp; "." &amp; hash  
\]; result )  
Calculate the signature for AWS Signature Version 4:

 Let ( \[   
  
// see https://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html  
  
date="20150830";  
Region = "us-east-1";  
Service= "iam";  
Signing= "aws4\_request";  
  
kSecret = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY";  
kDate = MBS ( "Hash.SHA256.HMAC"; "AWS4" &amp; kSecret ; date);  
kRegion = MBS ( "Hash.SHA256.HMAC”; kDate ; Region; 2);  
kService = MBS ( "Hash.SHA256.HMAC”; kRegion ; Service; 2);  
kSigning = MBS ( "Hash.SHA256.HMAC”; kService ; Signing; 2)  
  
\]; Lower (kSigning))  
<small>  
Example result: c4afb1cc5771d871763a393e44b703571b55cc28424d1a5e86da6ed3c154a4b9</small>Calculate hash for kaufland API:

 Let ( \[  
method = "POST";  
uri = "https://sellerapi.kaufland.com/v2/units/";  
body = "";  
timestamp = 1411055926;  
secretKey = "a7d0cb1da1ddbc86c96ee5fedd341b7d8ebfbb2f5c83cfe0909f4e57f05dd403";  
texts = method &amp; Char(10) &amp; uri &amp; Char(10) &amp; body &amp; Char(10) &amp; timestamp;  
result = MBS ( "Hash.SHA256.HMAC"; secretKey; texts; 0)  
\]; lower(result) )  
// see https://sellerapi.kaufland.com/?page=rest-api#signrequest-php  
<small>  
Example result: da0b65f51c0716c1d3fa658b7eaf710583630a762a98c9af8e9b392bd9df2e2a</small>### See also

- [Hash.SHA1.HMAC](HashSHA1HMAC.md)
- [Hash.SHA256](HashSHA256.md)
- [Hash.SHA512](HashSHA512.md)
- [Hash.SHA512.HMAC](HashSHA512HMAC.md)
- [Text.EncodeToBase64](TextEncodeToBase64.md)
- [Text.EncodeToBase64URL](TextEncodeToBase64URL.md)
- [Text.ReplaceNewLine](TextReplaceNewLine.md)

### Release notes

- **Version 10.3**
    - Added option for Base64URL encoding to [Hash.MD5](https://www.mbsplugins.eu/HashMD5.shtml), [Hash.MD5.HMAC](https://www.mbsplugins.eu/HashMD5HMAC.shtml), [Hash.SHA1](https://www.mbsplugins.eu/HashSHA1.shtml), [Hash.SHA1.HMAC](https://www.mbsplugins.eu/HashSHA1HMAC.shtml), [Hash.SHA256](https://www.mbsplugins.eu/HashSHA256.shtml), [Hash.SHA256.HMAC](https://www.mbsplugins.eu/HashSHA256HMAC.shtml), [Hash.SHA512](https://www.mbsplugins.eu/HashSHA512.shtml) and [Hash.SHA512.HMAC](https://www.mbsplugins.eu/HashSHA512HMAC.shtml) functions.

### Blog Entries

- [MBS FileMaker Plugin, version 10.3pr1](https://www.mbsplugins.de/archive/2020-06-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [JWT RS256 authentication in FileMaker](https://www.mbsplugins.de/archive/2020-05-28/JWT_RS256_authentication_in_Fi/monkeybreadsoftware_blog_filemaker)
- [Comparing Base Elements Plugin to MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2017-10-24/Comparing_Base_Elements_Plugin/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.0pr7](https://www.mbsplugins.de/archive/2016-01-20/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 4.0pr4](https://www.mbsplugins.de/archive/2014-01-19/MBS_Filemaker_Plugin_version_4/monkeybreadsoftware_blog_filemaker)

This function is free to use.

Created 18th August 2014 , last changed 24th February 2026

  
[Hash.SHA256](HashSHA256.md) - [Hash.SHA512](HashSHA512.md)

[HTML Version](HashSHA256HMAC.shtml)