Note: Import std/sha1 to use this module
SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function which takes an input and produces a 160-bit (20-byte) hash value known as a message digest.
import std/sha1 let accessName = secureHash("John Doe") assert $accessName == "AE6E4D1209F17B460503904FAD297B31E9CF6362"
import std/sha1 let a = secureHashFile("myFile.nim") b = parseSecureHash("10DFAEBF6BFDBC7939957068E2EFACEC4972933C") if a == b: echo "Files match"
See also:
- base64 module implements a base64 encoder and decoder
- hashes module for efficient computations of hash values for diverse Nim types
- md5 module implements the MD5 checksum algorithm
Procs
proc newSha1State(): Sha1State {...}{.raises: [], tags: [].}
- Source Edit
proc update(ctx: var Sha1State; data: openArray[char]) {...}{.raises: [], tags: [].}
- Source Edit
proc finalize(ctx: var Sha1State): Sha1Digest {...}{.raises: [], tags: [].}
- Source Edit
proc secureHash(str: openArray[char]): SecureHash {...}{.raises: [], tags: [].}
-
Generates a SecureHash from a str.
See also:
- secureHashFile proc for generating a SecureHash from a file
- parseSecureHash proc for converting a string hash to SecureHash
Example:
let hash = secureHash("Hello World") assert hash == parseSecureHash("0A4D55A8D778E5022FAB701977C5D840BBC486D0")
Source Edit proc secureHashFile(filename: string): SecureHash {...}{.raises: [IOError], tags: [ReadIOEffect].}
-
Generates a SecureHash from a file.
See also:
- secureHash proc for generating a SecureHash from a string
- parseSecureHash proc for converting a string hash to SecureHash
proc `$`(self: SecureHash): string {...}{.raises: [], tags: [].}
-
Returns the string representation of a SecureHash.
See also:
- secureHash proc for generating a SecureHash from a string
Example:
let hash = secureHash("Hello World") assert $hash == "0A4D55A8D778E5022FAB701977C5D840BBC486D0"
Source Edit proc parseSecureHash(hash: string): SecureHash {...}{.raises: [ValueError], tags: [].}
-
Converts a string hash to SecureHash.
See also:
- secureHash proc for generating a SecureHash from a string
- secureHashFile proc for generating a SecureHash from a file
Example:
let hashStr = "0A4D55A8D778E5022FAB701977C5D840BBC486D0" secureHash = secureHash("Hello World") assert secureHash == parseSecureHash(hashStr)
Source Edit proc `==`(a, b: SecureHash): bool {...}{.raises: [], tags: [].}
-
Checks if two SecureHash values are identical.
Example:
let a = secureHash("Hello World") b = secureHash("Goodbye World") c = parseSecureHash("0A4D55A8D778E5022FAB701977C5D840BBC486D0") assert a != b assert a == c
Source Edit