md5
nimony/lib/std/md5.nim
This module implements the MD5 message digest algorithm (RFC 1321).
.. warning:: MD5 is considered broken for cryptographic use (collisions are feasible). Use it only for checksums / non-security purposes.
It offers both the one-shot API (toMD5, getMD5, and $ on a digest) and the incremental MD5Context (md5Init / md5Update / md5Final) for hashing data that arrives in pieces.
type MD5Digest = array[0..15, uint8]Represents an MD5 digest (128 bits / 16 bytes).
type MD5Context = object state: array[0..3, uint32] length: uint64 buffer: array[0..63, uint8] bufLen: int64
func md5Init(c: var MD5Context)Initializes (or resets) an
MD5Contextso it is ready to hash a fresh message.func md5Update(c: var MD5Context; input: openArray)Feeds
inputinto the running digestc.func md5Update(c: var MD5Context; input: string)Feeds the bytes of
inputinto the running digestc.func md5Final(c: var MD5Context; digest: var array[0..15, uint8])Finishes the digest computation for
cand writes the 16-byte result intodigest. After this callcshould be re-initialized withmd5Initbefore being reused.func toMD5(msg: string): array[0..15, uint8]Computes the MD5 digest of
msg.func $(d: array[0..15, uint8]): stringConverts an
MD5Digestto its lowercase hexadecimal string.func getMD5(s: string): stringComputes the MD5 digest of
sand returns it as a lowercase hex string.