/
hasherSha1.go
56 lines (45 loc) · 1.32 KB
/
hasherSha1.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
package cpu
import (
"bytes"
"crypto/sha1"
"encoding/hex"
"github.com/ngirot/BruteForce/bruteforce/hashs/hashers"
"hash"
)
type hasherSha1 struct {
cache hash.Hash
}
func NewHasherSha1() hashers.Hasher {
return &hasherSha1{sha1.New()}
}
func (h *hasherSha1) ProcessWithWildcard(charSet []string, saltBefore string, saltAfter string, numberOfWildCards int, expectedDigest string) string {
return genericProcessWithWildCard(h, charSet, saltBefore, saltAfter, numberOfWildCards, expectedDigest)
}
func (h *hasherSha1) Example() string {
return hex.EncodeToString(h.Hash([]string{"1234567890"})[0])
}
func (h *hasherSha1) DecodeInput(data string) []byte {
var result, _ = hex.DecodeString(data)
return result
}
func (h *hasherSha1) Hash(datas []string) [][]byte {
var result = make([][]byte, len(datas))
for i, value := range datas {
result[i] = h.binaryHash(h.convert(value))
}
return result
}
func (h *hasherSha1) IsValid(data string) bool {
return hashers.GenericBase64Validator(h, data)
}
func (h *hasherSha1) Compare(transformedData []byte, referenceData []byte) bool {
return bytes.Equal(transformedData, referenceData)
}
func (h *hasherSha1) binaryHash(data []byte) []byte {
h.cache.Reset()
h.cache.Write([]byte(data))
return h.cache.Sum(nil)
}
func (h *hasherSha1) convert(s string) []byte {
return []byte(s)
}