/
hasherRipemd160.go
56 lines (45 loc) · 1.39 KB
/
hasherRipemd160.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"
"encoding/hex"
"github.com/ngirot/BruteForce/bruteforce/hashs/hashers"
"golang.org/x/crypto/ripemd160"
"hash"
)
type hasherRipemd160 struct {
cache hash.Hash
}
func NewHasherRipemd160() hashers.Hasher {
return &hasherRipemd160{ripemd160.New()}
}
func (h *hasherRipemd160) ProcessWithWildcard(charSet []string, saltBefore string, saltAfter string, numberOfWildCards int, expectedDigest string) string {
return genericProcessWithWildCard(h, charSet, saltBefore, saltAfter, numberOfWildCards, expectedDigest)
}
func (h *hasherRipemd160) Example() string {
return hex.EncodeToString(h.Hash([]string{"1234567890"})[0])
}
func (h *hasherRipemd160) DecodeInput(data string) []byte {
var result, _ = hex.DecodeString(data)
return result
}
func (h *hasherRipemd160) 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 *hasherRipemd160) IsValid(data string) bool {
return hashers.GenericBase64Validator(h, data)
}
func (h *hasherRipemd160) Compare(transformedData []byte, referenceData []byte) bool {
return bytes.Equal(transformedData, referenceData)
}
func (h *hasherRipemd160) binaryHash(data []byte) []byte {
h.cache.Reset()
h.cache.Write([]byte(data))
return h.cache.Sum(nil)
}
func (h *hasherRipemd160) convert(s string) []byte {
return []byte(s)
}