Video Coming Soon...
37: sha2sum
This exercise is pending. Quick notes about this exercise:
- My implemention is at https://lcthw.dev/go/go-coreutils
- https://www.gnu.org/software/coreutils/manual/html_node/sha2-utilities.html
- sha512 -- https://pkg.go.dev/crypto/sha512@go1.25.3
The Code
View Source file go-coreutils/sha512sum/main.go Only
package main
import (
"fmt"
"flag"
"os"
"log"
"crypto/sha512"
)
type Opts struct {
Inputs []string
}
func parse_opts() Opts {
var opts Opts
flag.Parse()
opts.Inputs = flag.Args()
return opts
}
func to_hex(hash [sha512.Size]byte) string {
result := ""
for _, b := range hash {
result += fmt.Sprintf("%x", b)
}
return result
}
func main() {
opts := parse_opts()
for _, fname := range opts.Inputs {
in_data, err := os.ReadFile(fname)
if err != nil { log.Fatal(err) }
hash := sha512.Sum512(in_data)
fmt.Println(to_hex(hash), fname)
}
}
Register for Learn Go the Hard Way
Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.