Encr_MakeDigest |
Generates a MD5 digest or a SHA-1 or SHA256 hash.
Syntax
Encr_MakeDigest ( switches ; text )
Parameters
| switches | determines the behavior of the function |
| text | the text to calculate the digest (hash) of |
Switches
Switches can be one of this:
| -md5 | use the MD5 algorithm |
| -sha1 | use the SHA-1 algorithm |
| -sha256 | use the SHA-256 algorithm |
You can also add one or more of the switches below:
| -hex | (default) output as a hex dump. This is the default for a "normal" digest as opposed to a digital signature. |
| -colons | add colons between the result |
| -uppercase | the digest (hash) is returned in upper case characters. |
| -Encoding=UTF8 | this will encode higher Unicode to UTF8 first, before calculating the digest. This is useful for for example Japanese or Chinese texts. |
| -DigestCompatibleWithv30 | generate the (incorrect) digests of v3.0, which only differ for digests of text bigger than 32000 characters. |
Returned Result
Data type returned
Text
Result
the digest, which is a string of bits.
MD5: a digest of 128 bits, formatted as 32 characters
SHA-1: a digest of 160 bits, formatted as 40 characters
SHA-256: a digest of 256 bits, formatted as 64 characters
The characters are all lower ASCII characters and therefore safe to send across internet.
Originated in
Troi Encryptor Plug-in 1.2
Compatibility
FileMaker Pro 18 to FileMaker Pro 2025
Considerations
Troi Encryptor Plug-in 6.0 added the switch -SHA256
v9.0 added the “-UpperCase” switch: when you add this switch the digest (hash) is returned in upper case characters.
What is MD5, SHA-1 and SHA256?
MD5: MD5 was developed by Prof. Rivest in 1994. Its 128 bit (16 characters) message digest makes it a faster implementation than SHA-1, but is no longer considered safe.
SHA-1 + SHA256 : The Secure Hash Algorithm (SHA) was developed by NIST and is specified in the Secure Hash Standard (SHS, FIPS 180). SHA-1 produces a 160-bit (20 bytes) message digest. SHA256 even has 256 bits (or 32 bytes) length. This larger digest size makes it stronger against brute force attacks.
Note that MD5 is no longer considered collision-free/unique. If possible use SHA-1. You can find more info on this here:
here.
Please note that we fixed a bug in v3.0.1 which was introduced in v3.0: when creating a MD5 digest an incorrect digest would be returned for texts bigger than 32000 characters. We have added a switch “-DigestsCompatibleWithv30” so you can generate the (incorrect) digests of v3.0 if needed.
Example
Encr_MakeDigest ( "-sha256" ;
"Here is a sample text that you can see the digest of." )
gives this result: “83347ed5310df566f6ead75129c02a61b05792dbb9a782e0d7c45bc0cbc11990”
If you add the “-colons” switch, the result is:
“83:34:7e:d5:31:0d:f5:66:f6:ea:d7:51:29:c0:2a:61:b0:57:92:db:b9:a7:82:e0:d7:c4:5b:c0:cb:c1:19:90”
If you use “-sha1” as switch, the result is:
“0e987e2893ba31b7b724d53991bf7b3d6bdabb75”
If you use “-sha1 -colons” as switches, the result is:
“0e:98:7e:28:93:ba:31:b7:b7:24:d5:39:91:bf:7b:3d:6b:da:bb:75”
Example 2
You can use this function to check if (the meaning of) a text was not changed, by adding the signature to the message.
Send Message [ message & "¶Sha256 Digest = " & Encr_MakeDigest ( "-sha256" ; message ) ]
At the receiving end you can define this in a script “Receive message with signature”:
Set Variable [ $MessageReceived; <set this to the incoming message> ) ]
Set Variable [ $SignatureTag; "¶Sha256 Digest = " ]
Set Variable [ $SignaturePos; Position ( $MessageReceived ; $SignatureTag ; 1 ; 1 ) ]
If [ $SignaturePos = 0 // not found! ]
Beep
Show Custom Dialog [ "The message does not contain a signature." ; "OK" ]
Exit Script [ Result: -1 ]
End If
Set Variable [ $MessageClean; Left ($MessageReceived ; $SignaturePos - 1 ) ]
Set Variable [ $SignatureReceived; Middle ( $MessageReceived ;
$SignaturePos + Length ( $SignatureTag ) ;
Length ( $MessageReceived ) ) ]
Set Variable [ $SignatureOfMessageReceived; Encr_MakeDigest ( "-sha256" ; $MessageClean ) ]
Set Variable [ $MessageIsUnchanged; $SignatureOfMessageReceived = $SignatureReceived ]
If [ $MessageIsUnchanged ]
Show Custom Dialog [ "The received message was not changed."; "OK" ]
Else
Beep
Show Custom Dialog [ "The received message differs from the sent message.
The signature is different."; "OK ]
End If
Used in example file
MakeDigest.fmp12
Related functions
| Encr_Checksum |
| Encr_TextSignature |
Related topics
Troi Encryptor Plug-in online help (overview)