-
-
Notifications
You must be signed in to change notification settings - Fork 0
5.4 hash payload
wiki[bot] edited this page Aug 23, 2026
·
1 revision
Generates cryptographic hashes for strings, objects, or binary data using Node.js crypto module.
import { hashPayload } from "@triplef/helpers/hash-payload";function hashPayload(
payload: string | Record<any, any> | Buffer | Uint8Array,
algorithm: HashPayloadSupportedAlgorithm = "sha256",
encoder: BinaryToTextEncoding = "hex"
): string;-
"sha256"(default) "sha384""sha512"
-
"hex"(default) - Hexadecimal string -
"base64"- Base64 encoded string -
"latin1"- Latin-1 encoded string
| Parameter | Type | Description |
|---|---|---|
payload |
string | object | Buffer | Uint8Array |
Data to hash |
algorithm |
HashPayloadSupportedAlgorithm |
Hash algorithm (default: "sha256") |
encoder |
BinaryToTextEncoding |
Output encoding (default: "hex") |
| Input Type | Behavior |
|---|---|
string |
Hashed directly with UTF-8 encoding |
object |
Automatically JSON.stringified before hashing |
Buffer |
Hashed directly |
Uint8Array |
Hashed directly |
// Hash a string (default SHA-256, hex encoded)
const hash1 = hashPayload("hello");
// Output: "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
// Hash an object (automatically JSON.stringified)
const hash2 = hashPayload({ foo: "bar" });
// Output: SHA-256 hash of '{"foo":"bar"}'
// SHA-512 with base64 encoding
const hash3 = hashPayload("data", "sha512", "base64");
// SHA-384
const hash4 = hashPayload(buffer, "sha384");
// Hash a Buffer
const buffer = Buffer.from("hello");
const hash5 = hashPayload(buffer);