Hash.Digest
-----------

Calculates a hash of a value.

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

MBS( "Hash.Digest"; Algorithm; InputType; InputData; InputEncoding; OutputType { ; OutputInfo } ) 

**MBS**( **"Hash.Digest";** /\* Calculates a hash of a value. \*/  
**$Algorithm**; /\* Which algorithm to use.   
Can be MD4, MD5, SHA, SHA1, MDC2, RIPEMD160, SHA224, SHA256, SHA384 or SHA512.e.g. "SHA512" \*/   
**$InputType**; /\* The type of input.   
Can be Text, Image, Path, PDF, Data, base64 or Hex.e.g. "Text" \*/   
**$InputData**; /\* The actual input data.   
Text, container or file path.e.g. "Hello World" \*/   
**$InputEncoding**; /\* The text encoding for text input.   
Parameter is ignored for other cases.e.g. "UTF-8" \*/   
**$OutputType**; /\* The output type.   
Can be Base64, Hex, Text, File, Path.  
Added Base64URL as option for plugin version 10.3.e.g. "Hex" \*/   
**$OutputInfo**) /\* Optional; The addition info for output.   
For text it is the text encoding, for file container the file name and for path the actual native file path.e.g. "" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| Algorithm | Which algorithm to use.    Can be MD4, MD5, SHA, SHA1, MDC2, RIPEMD160, SHA224, SHA256, SHA384 or SHA512. | "SHA512" |  |
| InputType | The type of input.    Can be Text, Image, Path, PDF, Data, base64 or Hex. | "Text" |  |
| InputData | The actual input data.    Text, container or file path. | "Hello World" |  |
| InputEncoding | The text encoding for text input.    Parameter is ignored for other cases.   Possible encoding names: ANSI, ISO-8859-1, Latin1, Mac, Native, UTF-8, DOS, Hex, Base64 or Windows. More listed in the [FAQ](https://www.monkeybreadsoftware.com/filemaker/faq.shtml). | "UTF-8" |  |
| OutputType | The output type.    Can be Base64, Hex, Text, File, Path.   Added Base64URL as option for plugin version 10.3. | "Hex" |  |
| OutputInfo | The addition info for output.    For text it is the text encoding, for file container the file name and for path the actual native file path. | "" | Optional |

### Result

Returns error or hash.

### Description

Calculates a hash of a value.  
Input can be one of different types:  
- Text, you pass "text", your text and the text encoding. If no or invalid encoding name is passed, the native one is used. The encoding can be one of the following strings: ansi, windows, mac, latin1, utf8, dos or native.
- PDF, you pass the container with the PDF file inside.
- Image, you pass the container with an image file (JPEG, GIF, TIFF, PNG, PICT).
- Data, you pass container and plugin looks for the file data inside.
- Hex, you pass a hex encoded text.
- Base64, you pass a base64 encoded text.
- Path, you pass the file path to a file to read.
- Container, you pass a container which is packed with all its content.

Now for output we can return the digest in various ways:  
- Text, we return the hash as text in the encoding. This is not recommended for hash values. OutputInfo parameter is text encoding.
- Base64, the hash is returned as base64 encoded text.
- Hex, the hash is returned as hex encoded text.
- File, the hash is returned as a container value with a file inside containing the hash. OutputInfo parameter is the filename to be stored in the container value.
- Path, the hash is written to a file. In the OutputInfo parameter you provide a native file path.
- JPEG, a container with a JPEG image.
- GIF, a container with a GIF image.
- TIFF, a container with a TIFF image.
- PNG, a container with a PNG image.

Possible digest engines:   
DSA-SHA, DSA, MD5, MDC2, RIPEMD160, SHA, SHA1, SHA224, SHA256, SHA384 or SHA512.   
  
This function requires a native path. Use [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md) to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use [FileDialog](component_FileDialog.md) functions.  
For Server be aware that server has limited permissions and may not be able to access all files on a computer.  
### Examples

Calculate MD5 from text:

 MBS ( "Hash.Digest"; "MD5"; "Text"; "Hello World"; "UTF-8"; "Hex"; "" )  
Calculate SHA512 from image in container and encode it as base64:

 MBS ( "Hash.Digest"; "SHA512"; "Image"; MyTable::MyContainer ; ""; "Base64"; "" )  
Hash of PDF in container:

 MBS ( "Hash.Digest"; "SHA512"; "PDF"; MyTable::MyContainer ; ""; "Hex"; "" )  
Hash a file with MD5:

 MBS ( "Hash.Digest"; "MD5"; "Path"; "/Users/cs/Desktop/test.fmp12"; ""; "Hex"; "" )  
Stream file to AWS:

 # Build a path to file (local) and in AWS   
Set Variable \[ $Filename ; Value: "test.pdf" \]   
Set Variable \[ $Path ; Value: "/" &amp; $BucketName &amp; "/PDF/" &amp; $Filename \]   
Set Variable \[ $localPath ; Value: "/Users/cs/Desktop/license.pdf" \]   
\# calculate hash for file to upload   
Set Variable \[ $HashedPayload ; Value: Lower(MBS ( "Hash.Digest"; "sha256"; "path"; $localPath ; ""; "hex" )) \]   
\# upload   
Set Variable \[ $curl ; Value: MBS ("[CURL.New](CURLNew.md)") \]   
\# file content is streamed   
Set Variable \[ $result ; Value: MBS ("[CURL.OpenInputFile](CURLOpenInputFile.md)"; $curl ; $localPath ) \]   
\# setup AWS   
Set Variable \[ $result ; Value: MBS ("[CURL.SetupAWS](CURLSetupAWS.md)"; $curl ; $AWSAccessKeyId ; $AWSSecretAccessKey ; $Region ; $Service ; $Path ; $Domain ; $Verb ; $HashedPayload ; $headers ) \]   
Set Field \[ CURL Test::Result ; MBS ("[CURL.Perform](CURLPerform.md)"; $curl ) \]   
Set Field \[ CURL Test::debug ; MBS ("[CURL.GetDebugMessages](CURLGetDebugMessages.md)"; $curl ) \]   
Set Variable \[ $result ; Value: MBS ("[CURL.Release](CURLRelease.md)"; $curl ) \]  
Use SHA-3:

 MBS ( "Hash.Digest"; "RSA-SHA3-256"; "Text"; "Hello World"; "UTF-8"; "Hex"; "" )  
<small>  
Example result: E167F68D6563D75BB25F3AA49C29EF612D41352DC00606DE7CBD630BB2665F51</small>Calculate x5t for a certificate file:

 Let ( \[  
// read PEM file  
cert = MBS ( "X509.ReadFromFile"; "/Users/cs/Downloads/Cert.pem" );  
// write DER file  
data = MBS ( "X509.Write"; cert; 1 );  
// and free memory  
r = MBS ( "X509.Release"; cert );  
// hash it to get x5t  
hash = MBS ( "Hash.Digest"; "SHA1"; "Base64"; data; ""; "base64url")  
\]; hash )  
Do Shake128 with default 16 byte result:

 MBS ( "Hash.Digest"; "Shake128"; "Text"; "Hello World"; "UTF-8"; "Hex"; "" )  
<small>  
Example result: 1227C5F882F9C57BF2E3E48D2C87EB20</small>### See also

- [CURL.OpenInputFile](CURLOpenInputFile.md)
- [CURL.Perform](CURLPerform.md)
- [CURL.SetupAWS](CURLSetupAWS.md)
- [Encryption.Cipher](EncryptionCipher.md)
- [GMImage.Hash](GMImageHash.md)
- [Hash.SHA1](HashSHA1.md)
- [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md)
- [X509.Read](X509Read.md)
- [X509.ReadFromFile](X509ReadFromFile.md)
- [X509.Release](X509Release.md)

### Release notes

- **Version 16.1**
    - Improved [Hash.Digest](https://www.mbsplugins.eu/HashDigest.shtml) and [Hash.DigestFile](https://www.mbsplugins.eu/HashDigestFile.shtml) functions to work with shake128 and shake256.
- **Version 15.5**
    - Fixed [ProgressDialog](https://www.mbsplugins.eu/component_ProgressDialog.shtml) functions to work better if you run [Hash.DigestFile](https://www.mbsplugins.eu/HashDigestFile.shtml) and click cancel.
- **Version 14.2**
    - Added parameter for [Hash.DigestFile](https://www.mbsplugins.eu/HashDigestFile.shtml) to update progress dialog.
- **Version 10.3**
    - Added Base64URL as output option for [RSA.Sign](https://www.mbsplugins.eu/RSASign.shtml), [CURL.ReceiveData](https://www.mbsplugins.eu/CURLReceiveData.shtml), [Files.ReadFile](https://www.mbsplugins.eu/FilesReadFile.shtml), [Hash.DigestFile](https://www.mbsplugins.eu/HashDigestFile.shtml), [Hash.Digest](https://www.mbsplugins.eu/HashDigest.shtml), [Encryption.Cipher](https://www.mbsplugins.eu/EncryptionCipher.shtml) and for other functions as text encoding parameter.
- **Version 9.5**
    - Fixed crash in [Hash.Digest](http://www.mbsplugins.eu/HashDigest.shtml) function when passing invalid file path for file.
- **Version 9.2**
    - Added [Hash.DigestFile](http://www.mbsplugins.eu/HashDigestFile.shtml) function to calculate hashes of big files.

### Example Databases

- [CURL/Amazon S3/Amazon S3 Upload File](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Amazon%20S3/Amazon%20S3%20Upload%20File.shtml#5ScriptAnchor_)
- [Encryption and Hash/AES with PHP/AES with PHP](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Encryption%20and%20Hash/AES%20with%20PHP/AES%20with%20PHP.shtml#1ScriptAnchor_)
- [Encryption and Hash/Hash Digest](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Encryption%20and%20Hash/Hash%20Digest.shtml#1ScriptAnchor_)
- [SmartCard/Belgian EID Reader](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SmartCard/Belgian%20EID%20Reader.shtml#14ScriptAnchor_)
- [Third Party/FileMaker Snippet Storage](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Third%20Party/FileMaker%20Snippet%20Storage.shtml#13CustomFunctionAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 16.1pr5](https://www.mbsplugins.de/archive/2026-03-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 10.3pr1](https://www.mbsplugins.de/archive/2020-06-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.5pr3](https://www.mbsplugins.de/archive/2019-10-13/MBS_FileMaker_Plugin_version_9/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)
- [AES in FileMaker and PHP](https://www.mbsplugins.de/archive/2016-01-07/AES_in_FileMaker_and_PHP/monkeybreadsoftware_blog_filemaker)
- [New universal Hash and Encrypt functions for MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2014-02-23/New_universal_Hash_and_Encrypt/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 4.1pr2](https://www.mbsplugins.de/archive/2014-02-21/MBS_Filemaker_Plugin_version_4/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

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

  
[Hash.CRC32](HashCRC32.md) - [Hash.DigestFile](HashDigestFile.md)

[HTML Version](HashDigest.shtml)