Note: In order to use this module, run nimble install checksums.

Module for computing MD5 checksums.

Be aware that using MD5 for cryptographic purposes is strongly discouraged as it is no longer deemed secure enough even against consumer grade computational resources.

This module also works at compile time and in JavaScript.

See also

Types

  1. MD5Context {.final.} = object
  1. MD5Digest = array[0 .. 15, uint8]

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

Procs

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

Converts a MD5Digest value into its string representation.

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

Checks if two MD5Digest values are identical.

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

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

See also:

  • toMD5 proc which returns the MD5Digest of a string

Example:

  1. assert getMD5("abc") == "900150983cd24fb0d6963f7d28e17f72"
  1. proc md5Final(c: var MD5Context; digest: var MD5Digest) {....raises: [], tags: [],
  2. gcsafe, forbids: [].}
  1. proc md5Init(c: var MD5Context) {....raises: [], tags: [], gcsafe, forbids: [].}
  1. proc md5Update(c: var MD5Context; input: cstring; len: int) {....raises: [],
  2. tags: [], gcsafe, forbids: [].}

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.

  1. proc md5Update(c: var MD5Context; input: openArray[uint8]) {....raises: [],
  2. tags: [], gcsafe, forbids: [].}
  1. proc toMD5(s: string): MD5Digest {....raises: [], tags: [], forbids: [].}

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:

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