Skip to content

HashString (hash a string)

ts
function HashString(algorithm: string, text: string): string;

NOTE

This function is available as of Syncplify Server! v7.1.1. If you are running an older version, upgrade to v7.1.1 or later to use it.

Computes the hash of text and returns it as a lowercase hexadecimal string. Use this to verify data integrity, create deterministic identifiers, or compute checksums of in-memory strings.

To hash a file on disk, use HashFile instead.

ParameterTypeRequirementExplanation
algorithmstringrequiredHash algorithm to use (see table below)
textstringrequiredThe string to hash
Return valueExplanation
stringLowercase hex-encoded hash of the input

Supported algorithms

ValueAlgorithm
md5MD5 (128-bit) — not recommended for security use
sha1SHA-1 (160-bit) — not recommended for security use
sha256SHA-256 (256-bit)
sha384SHA-384 (384-bit)
sha512SHA-512 (512-bit)
sha3256SHA3-256 (256-bit)
sha3384SHA3-384 (384-bit)
sha3512SHA3-512 (512-bit)

NOTE

If an unrecognised algorithm name is supplied, SHA-256 is used as the default and a debug-level log entry is written.

Example

ts
var digest = HashString('sha256', 'Hello, World!');
Log('SHA-256: ' + digest);
// dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986d