Skip to main content

MD5HashHex

Function MD5HashHex( const Input : String) : String

Example

procedure ScriptEvent(var Value: Variant);
begin
Value := MD5HashHex('fictional integration payload');
// Non-empty input produces 32 lowercase hexadecimal characters.
end;

Usage

MD5HashHex returns a hexadecimal MD5 digest of non-empty UTF-8 text.

Parameters

NameTypeDescription
InputString, constText to hash. Non-empty input is converted to UTF-8 without trimming or Unicode normalisation.

Returns

For non-empty input, 32 lowercase hexadecimal characters using 0-9 and a-f. Empty input returns '', not the standard MD5 text for an empty byte sequence.

Behaviour

  • Output is deterministic, unsalted and unkeyed.
  • Input is text encoded as UTF-8; this is not a raw-byte or file hashing helper.
  • Casing is part of the public representation: alphabetic digits are lowercase.
  • No prefix, separator or line break is added.

Errors

UTF-8 conversion, allocation and hash failures propagate. There is no error flag or sentinel other than the deliberate empty-input result.

Additional Technical Info

MD5HashHex calculates MD5 over a string's UTF-8 bytes and returns the 16-byte digest as 32 lowercase hexadecimal characters. Use it only when a legacy integration contract explicitly requires MD5 text in this form.

The example is source-reviewed and was not executed by the documentation workflow.

Implementation

Velox first exits with an empty result when Input = ''. Otherwise it calls the installed Delphi 37.0 string overload System.Hash.THashMD5.GetHashString. Delphi creates an MD5 record, feeds it TEncoding.UTF8.GetBytes(Input), finalises the 16-byte digest and converts each nibble through its lowercase hexadecimal table.

Edge cases and quirks

  • Empty input returns '' because of the Velox wrapper, even though the Delphi terminal can hash an empty string.
  • MD5 has practical collision attacks and is unsuitable for security-sensitive identity, integrity, password or authentication decisions.
  • LoadAndHashFile and MD5HashStream use shipped Indy and emit uppercase hexadecimal; string comparison is therefore case-sensitive unless the caller normalises a representation intentionally.
  • Free Pascal MD5String hashes RawByteString bytes. Its input bytes can differ from Velox UTF-8 for non-ASCII text.
  • Visually identical Unicode strings are not normalised and can produce different results.

Side effects

None beyond temporary managed memory.

Performance and concurrency

Time and temporary input storage are linear in UTF-8 byte length. Each call uses local hash state, so independent calls do not share mutable state.

Remarks

When persisting or comparing the result, record MD5, UTF-8 and lowercase hexadecimal as part of the data contract. Hexadecimal casing does not change the digest bytes, but it does affect ordinary string equality.

Related entries

  • MD5Hash returns the same digest bytes as padded Base64.
  • MD5HashStream hashes remaining stream bytes and returns uppercase hexadecimal.
  • SHA1HashHex provides the corresponding legacy SHA-1 representation.
  • HashString provides a stronger SHA-384 text fingerprint.

External references

Created 2026-07-15