/
encode.go
79 lines (66 loc) · 1.71 KB
/
encode.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package encode
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/base32"
"encoding/base64"
"hash/fnv"
)
// Base32Encode base32 encode
func Base32Encode(data []byte) string {
return base32.StdEncoding.EncodeToString(data)
}
// Base32Decode base32 decode
func Base32Decode(data string) ([]byte, error) {
return base32.StdEncoding.DecodeString(data)
}
// Base64Encode base64 encode
func Base64Encode(data []byte) string {
return base64.StdEncoding.EncodeToString(data)
}
// Base64Decode base64 decode
func Base64Decode(data string) ([]byte, error) {
return base64.StdEncoding.DecodeString(data)
}
// FNV32 hashes using fnv32 algorithm
func FNV32(text string) uint32 {
algorithm := fnv.New32()
return uint32Hasher(algorithm, text)
}
// FNV32a hashes using fnv32a algorithm
func FNV32a(text string) uint32 {
algorithm := fnv.New32a()
return uint32Hasher(algorithm, text)
}
// FNV64 hashes using fnv64 algorithm
func FNV64(text string) uint64 {
algorithm := fnv.New64()
return uint64Hasher(algorithm, text)
}
// FNV64a hashes using fnv64a algorithm
func FNV64a(text string) uint64 {
algorithm := fnv.New64a()
return uint64Hasher(algorithm, text)
}
// MD5 hashes using md5 algorithm
func MD5(text string) string {
algorithm := md5.New()
return stringHasher(algorithm, text)
}
// SHA1 hashes using sha1 algorithm
func SHA1(text string) string {
algorithm := sha1.New()
return stringHasher(algorithm, text)
}
// SHA256 hashes using sha256 algorithm
func SHA256(text string) string {
algorithm := sha256.New()
return stringHasher(algorithm, text)
}
// SHA512 hashes using sha512 algorithm
func SHA512(text string) string {
algorithm := sha512.New()
return stringHasher(algorithm, text)
}