Hashing large files

In the previous hashing example, the entire file to be hashed was loaded into memory before hashing. This is not practical or even possible when files reach a certain size. Physical memory limitations will come into play. Because the hashes are implemented as a block cipher, it will operate on one chunk at a time without the need to load the entire file in memory at once:

package mainimport (   "crypto/md5"   "fmt"   "io"   "log"   "os")func printUsage() {   fmt.Println("Usage: " + os.Args[0] + " <filename>")   fmt.Println("Example: " + os.Args[0] + " diskimage.iso")}func checkArgs() string {   if len(os.Args) < 2 {      printUsage()      os.Exit(1)   }   return os.Args[1]}func main() {   filename := checkArgs()   // Open file for reading file, err := ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.