-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.go
63 lines (46 loc) · 1.16 KB
/
checker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"bufio"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"errors"
"fmt"
"io"
"os"
"github.com/gookit/color"
)
func generateHashes(filePath string) error {
file, err := os.Open(filePath)
if err != nil {
return errors.New("error in reading the file")
}
defer file.Close()
stat, err := file.Stat()
if err != nil {
return errors.New("error returning the File Info")
}
bs := make([]byte, stat.Size())
_, err = bufio.NewReader(file).Read(bs)
if err != nil && err != io.EOF {
return errors.New("error in parsing the file")
}
color.Cyan.Println("MD5:")
fmt.Printf("%x\n\n", md5.Sum(bs))
color.Cyan.Println("Sha1:")
fmt.Printf("%x\n\n", sha1.Sum(bs))
color.Cyan.Println("Sha224:")
fmt.Printf("%x\n\n", sha256.Sum224(bs))
color.Cyan.Println("Sha256:")
fmt.Printf("%x\n\n", sha256.Sum256(bs))
color.Cyan.Println("Sum384:")
fmt.Printf("%x\n\n", sha512.Sum384(bs))
color.Cyan.Println("Sha512:")
fmt.Printf("%x\n\n", sha512.Sum512(bs))
color.Cyan.Println("SHA512_224:")
fmt.Printf("%x\n\n", sha512.Sum512_224(bs))
color.Cyan.Println("SHA512_256:")
fmt.Printf("%x\n\n", sha512.Sum512_256(bs))
return nil
}