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.
| Parameter | Type | Requirement | Explanation |
|---|---|---|---|
algorithm | string | required | Hash algorithm to use (see table below) |
text | string | required | The string to hash |
| Return value | Explanation |
|---|---|
| string | Lowercase hex-encoded hash of the input |
Supported algorithms
| Value | Algorithm |
|---|---|
md5 | MD5 (128-bit) — not recommended for security use |
sha1 | SHA-1 (160-bit) — not recommended for security use |
sha256 | SHA-256 (256-bit) |
sha384 | SHA-384 (384-bit) |
sha512 | SHA-512 (512-bit) |
sha3256 | SHA3-256 (256-bit) |
sha3384 | SHA3-384 (384-bit) |
sha3512 | SHA3-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