/
sha3.go
41 lines (31 loc) · 813 Bytes
/
sha3.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
package hash
import (
"crypto"
"golang.org/x/crypto/sha3"
)
// https://pkg.go.dev/golang.org/x/crypto/sha3
func SHA3512(value []byte) []byte {
hashValue := crypto.SHA3_512.New()
hashValue.Write(value)
hashResult := hashValue.Sum(nil)
return hashResult
}
func SHA3512String(value []byte) string {
return string(SHA3512(value))
}
func SHA3512Verify(value []byte, hashValue string) bool {
return SHA3512String(value) == hashValue
}
// 非标准SHA3 Keccak
func Keccak512(value []byte) []byte {
hashValue := sha3.NewLegacyKeccak512()
hashValue.Write(value)
hashResult := hashValue.Sum(nil)
return hashResult
}
func Keccak512String(value []byte) string {
return string(Keccak512(value))
}
func Keccak512Verify(value []byte, hashValue string) bool {
return Keccak512String(value) == hashValue
}