Digest.MD5(3)

πŸ’… Digest.MD5(3) πŸ’…

Ok bestie, welcome to the Digest.MD5(3) page from the OCaml library β€” we're talking about the Digest.MD5 module, and yes, it's giving very specific hash-function energy. Let's get into it πŸ’–


✨ NAME ✨

Digest.MD5 β€” MD5 is the MD5 hash function. No cap, that's literally the name and the job 🌸


🧩 Module 🧩

  • Module: Digest.MD5 β€” that's the module we're living in, bestie 🫢

πŸ’– Documentation πŸ’–

  • Module MD5 : S β€” the signature situation, exactly as written.

MD5 is the MD5 hash function. It produces 128-bit (16-byte) digests, and it is not cryptographically secure at all. Like, do not use it for security, fr fr 😭 It should be used only for compatibility with earlier designs that mandate the use of MD5. That's the whole vibe: legacy compatibility, not main character security energy πŸ’€

✨ Since 5.2 ✨

  • type t = string β€” the type of digests. That's the digest representation right there πŸŽ€
  • val hash_length : int β€” the length of digests, in bytes. Short, sweet, and exactly what it says πŸ’…
  • val compare : t -> t -> int β€” compare two digests, with the same specification as compare. Bestie, it's the comparison behavior you already know and love 🌈
  • val equal : t -> t -> bool β€” test two digests for equality. Simple vibe check: equal or not equal πŸ¦‹
  • val string : string -> t β€” return the digest of the given string. String goes in, digest comes out ✨
  • val bytes : bytes -> t β€” return the digest of the given byte sequence. Byte-sequence bestie gets the same treatment πŸ’œ
  • val substring : string -> int -> int -> t β€” substring s ofs len returns the digest of the substring of s starting at index ofs and containing len characters. Slice that string, hash that slice, periodt πŸ“
  • val subbytes : bytes -> int -> int -> t β€” subbytes s ofs len returns the digest of the subsequence of s starting at index ofs and containing len bytes. Same idea, but the byte-sequence edition 🧚
  • val channel : in_channel -> int -> t β€” read characters from the channel and return their digest. See Digest.channel for the full specification. Go check that one for the whole story, iykyk πŸ‘‘
  • val file : string -> t β€” return the digest of the file whose name is given. Give it a filename, get a digest πŸŽ€
  • val output : out_channel -> t -> unit β€” write a digest on the given output channel. Digest goes out through the channel, slay πŸ’…
  • val input : in_channel -> t β€” read a digest from the given input channel. Digest comes in from the channel, iconic πŸ¦‹
  • val to_hex : t -> string β€” return the printable hexadecimal representation of the given digest. Hex string era ✨

Raises Invalid_argument if the length of the argument is not hash_length, 😭

  • val of_hex : string -> t β€” convert a hexadecimal representation back into the corresponding digest. Hex string goes back to digest form, no cap πŸ’–

Raises Invalid_argument if the length of the argument is not 2 * hash_length, or if the arguments contains non-hexadecimal characters. That's the guardrail, bestie 🚧


Cute sign-off time 🫢: this little page came from OCamldoc, dated 2026-06-22, and it's the Digest.MD5(3) manual page. Bye bestie, stay hashing responsibly πŸ’œβœ¨

πŸ“¦ where this page comes from