Skip to main content

Crypto module · hash implementation

Use MD5 when compatibility is the requirement.

MD5Hash implements the shared Hash API for legacy file formats, cache keys, and interoperability cases. It should not be used for new security-sensitive designs.

Know the boundary

Separate interoperability from security.

MD5 remains useful when an external protocol or existing dataset specifies it. For collision-resistant integrity or authentication, choose a modern cryptographic construction instead.

Use it for

Legacy formats and compatibility checks

Interface

Shared async, sync, and batch methods

Synchronous hashing

JavaScript implementation; no preload required

Avoid for

New security-sensitive applications

Detailed guide

MD5Hash details

The reference below documents the constructor and shared Hash behavior.

MD5Hash

From-v3.0

Calculates the MD5 hash. Asynchronous hashing rejects if WASM initialization or hashing fails.

Interface​

Implements the Hash API.

Methods​

constructor(options?: object)​

hashSync(input: ArrayBuffer, encoding: 'hex' | 'base64'): string​

Calculates an MD5 digest synchronously using the vendored JavaScript implementation. No preload or WebAssembly initialization is required. hash() continues to use WebAssembly for larger inputs when it is available.

import {MD5Hash} from '@loaders.gl/crypto/md5';

const input = new TextEncoder().encode('hello').buffer;
const digest = new MD5Hash().hashSync(input, 'hex');
// '5d41402abc4b2a76b9719d911017c592'