# std/md5

Dark Mode

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Source Edit

Module for computing MD5 checksums.

Note: The procs in this module can be used at compile time.

# See also

- base64 module implements a Base64 encoder and decoder
- std/sha1 module for a SHA-1 encoder and decoder
- hashes module for efficient computations of hash values for diverse Nim types

# Types

    MD5Context {.final.} = object
      state: MD5State
      count: array[0 .. 1, uint32]
      buffer: MD5Buffer

  Source Edit

    MD5Digest = array[0 .. 15, uint8]

  MD5 checksum of a string, obtained with the toMD5 proc. Source Edit

# Procs

    proc `$`(d: MD5Digest): string {....raises: [], tags: [].}

  Converts a `MD5Digest` value into its string representation. Source Edit

    proc `==`(D1, D2: MD5Digest): bool {....raises: [], tags: [].}

  Checks if two `MD5Digest` values are identical. Source Edit

    proc getMD5(s: string): string {....raises: [], tags: [].}

  Computes an MD5 value of `s` and returns its string representation.

  See also:

  - toMD5 proc which returns the `MD5Digest` of a string

  Example:

      assert getMD5("abc") == "900150983cd24fb0d6963f7d28e17f72"

  Source Edit

    proc md5Final(c: var MD5Context; digest: var MD5Digest) {....raises: [], tags: [],
        gcsafe.}

  Finishes the `MD5Context` and stores the result in `digest`.

  If you use the toMD5 proc, there's no need to call this function explicitly.

  Source Edit

    proc md5Init(c: var MD5Context) {....raises: [], tags: [], gcsafe.}

  Initializes an `MD5Context`.

  If you use the toMD5 proc, there's no need to call this function explicitly.

  Source Edit

    proc md5Update(c: var MD5Context; input: cstring; len: int) {....raises: [],
        tags: [], gcsafe.}

  Updates the `MD5Context` with the `input` data of length `len`.

  If you use the toMD5 proc, there's no need to call this function explicitly.

  Source Edit

    proc toMD5(s: string): MD5Digest {....raises: [], tags: [].}

  Computes the `MD5Digest` value for a string `s`.

  See also:

  - getMD5 proc which returns a string representation of the `MD5Digest`
  - $ proc for converting MD5Digest to string

  Example:

      assert $toMD5("abc") == "900150983cd24fb0d6963f7d28e17f72"

  Source Edit