md5namespacenamespace md5MD5 (RFC 1321), which Web Crypto does not give, for the protocols that still ask for it: S3's Content-MD5 header (the digest in base64), the ETag of an S3 object put in one part, and old checksum files (commons 0001-crypto FR-002).
MD5 is NOT for security: collisions are made in seconds, so it MUST NOT check that bytes are the ones expected against anyone who could choose them, sign, or hash a password. Use SHA-256 (./sha256.ts) for that; MD5 here only answers a protocol that names it.
The digest is given whole (md5, md5Hex) or a piece at a time (Md5, and md5Stream for a ReadableStream), so a file larger than memory is digested as it is read.
import { Md5, md5Hex } from "./md5.ts";
md5Hex("abc"); // "900150983cd24fb0d6963f7d28e17f72"
new Md5().update("a").update("bc").hex(); // the samemd5namespacenamespace md5md5.Md5classclass Md5An MD5 digest computed a piece at a time: update with each piece of the bytes in order (text is taken as UTF-8), then digest or hex. After the digest is taken, the object takes no more bytes. Not for security (see the module's documentation).
| Member | Type | What it is |
|---|---|---|
update | (data: string | Uint8Array<ArrayBufferLike>) => Md5 | Takes the next piece of the bytes; throws where the digest was already taken. |
digest | () => Uint8Array<ArrayBufferLike> | The 16 bytes of the digest of every piece taken; the same each time it is asked. |
hex | () => string | The digest as 32 lower-case hexadecimal digits. |
md5.md5functionfunction md5(data: string | Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>The 16 bytes of the MD5 of bytes, or of text as UTF-8. Not for security.
md5.md5Hexfunctionfunction md5Hex(data: string | Uint8Array<ArrayBufferLike>): stringThe MD5 of bytes, or of text as UTF-8, as 32 lower-case hexadecimal digits (md5("") is d41d8cd98f00b204e9800998ecf8427e).
md5.md5Streamfunctionfunction md5Stream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): Promise<Uint8Array<ArrayBufferLike>>The 16 bytes of the MD5 of every byte of a stream, read a chunk at a time, so the whole is never held. Not for security.
Md5classclass Md5An MD5 digest computed a piece at a time: update with each piece of the bytes in order (text is taken as UTF-8), then digest or hex. After the digest is taken, the object takes no more bytes. Not for security (see the module's documentation).
| Member | Type | What it is |
|---|---|---|
update | (data: string | Uint8Array<ArrayBufferLike>) => Md5 | Takes the next piece of the bytes; throws where the digest was already taken. |
digest | () => Uint8Array<ArrayBufferLike> | The 16 bytes of the digest of every piece taken; the same each time it is asked. |
hex | () => string | The digest as 32 lower-case hexadecimal digits. |
md5Hexfunctionfunction md5Hex(data: string | Uint8Array<ArrayBufferLike>): stringThe MD5 of bytes, or of text as UTF-8, as 32 lower-case hexadecimal digits (md5("") is d41d8cd98f00b204e9800998ecf8427e).
md5Streamfunctionfunction md5Stream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): Promise<Uint8Array<ArrayBufferLike>>The 16 bytes of the MD5 of every byte of a stream, read a chunk at a time, so the whole is never held. Not for security.