-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
135 lines (119 loc) · 3.75 KB
/
main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Package main - example implementation of different hashing algorithms
package main
import (
"crypto/sha256"
"crypto/sha512"
"fmt"
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/sha3"
// "github.com/zeebo/blake3"
)
/*
SHA256 // import crypto/sha256
SHA384 // import crypto/sha512
SHA512 // import crypto/sha512
SHA3_256 // import golang.org/x/crypto/sha3
SHA3_384 // import golang.org/x/crypto/sha3
SHA3_512 // import golang.org/x/crypto/sha3
SHA512_256 // import crypto/sha512
BLAKE2b_256 // import golang.org/x/crypto/blake2b
BLAKE2b_384 // import golang.org/x/crypto/blake2b
BLAKE2b_512 // import golang.org/x/crypto/blake2b
*/
func main() {
data := []byte("hello world")
optionalKey := []byte("secret")
// calculate SHA2-256 hash
sha256Hash := sha256.Sum256(data)
fmt.Println("sha256Hash:")
fmt.Println(sha256Hash)
fmt.Printf("hex: %x\n", sha256Hash)
fmt.Println("length", len(sha256Hash))
fmt.Println("")
// calculate SHA2-384 hash
sha384Hash := sha512.Sum384(data)
fmt.Println("sha384Hash:")
fmt.Println(sha384Hash)
fmt.Printf("hex: %x\n", sha384Hash)
fmt.Println("length", len(sha384Hash))
fmt.Println("")
// calculate SHA2-512 hash
sha512Hash := sha512.Sum512(data)
fmt.Println("sha512Hash:")
fmt.Println(sha512Hash)
fmt.Printf("hex: %x\n", sha512Hash)
fmt.Println("length", len(sha512Hash))
fmt.Println("")
// calculate SHA3-256 hash
sha3_256Hash := sha3.Sum256(data)
fmt.Println("sha3_256Hash:")
fmt.Println(sha3_256Hash)
fmt.Printf("hex: %x\n", sha3_256Hash)
fmt.Println("length", len(sha3_256Hash))
fmt.Println("")
// calculate SHA3-384 hash
sha3_384Hash := sha3.Sum384(data)
fmt.Println("sha3_384Hash:")
fmt.Println(sha3_384Hash)
fmt.Printf("hex: %x\n", sha3_384Hash)
fmt.Println("length", len(sha3_384Hash))
fmt.Println("")
// calculate SHA3-512 hash
sha3_512Hash := sha3.Sum512(data)
fmt.Println("sha3_512Hash:")
fmt.Println(sha3_512Hash)
fmt.Printf("hex: %x\n", sha3_512Hash)
fmt.Println("length", len(sha3_512Hash))
fmt.Println("")
// calculate SHA2-512/256 hash
sha512_256Hash := sha512.Sum512_256(data)
fmt.Println("sha512_256Hash:")
fmt.Println(sha512_256Hash)
fmt.Printf("hex: %x\n", sha512_256Hash)
fmt.Println("length", len(sha512_256Hash))
fmt.Println("")
// calculate BLAKE2b-256 hash
blake2b256Hash, _ := blake2b.New256(optionalKey)
blake2b256Hash.Write(data)
blake2b256Sum := blake2b256Hash.Sum(nil)
fmt.Println("blake2b256Sum:")
fmt.Println(blake2b256Sum)
fmt.Printf("hex: %x\n", blake2b256Sum)
fmt.Println("length", len(blake2b256Sum))
fmt.Println("")
// calculate BLAKE2b-384 hash
blake2b384Hash, _ := blake2b.New384(optionalKey)
blake2b384Hash.Write(data)
blake2b384Sum := blake2b384Hash.Sum(nil)
fmt.Println("blake2b384Sum:")
fmt.Println(blake2b384Sum)
fmt.Printf("hex: %x\n", blake2b384Sum)
fmt.Println("length", len(blake2b384Sum))
fmt.Println("")
// calculate BLAKE2b-512 hash
blake2b512Hash, _ := blake2b.New512(optionalKey)
blake2b512Hash.Write(data)
blake2b512Sum := blake2b512Hash.Sum(nil)
fmt.Println("blake2b512Sum:")
fmt.Println(blake2b512Sum)
fmt.Printf("hex: %x\n", blake2b512Sum)
fmt.Println("length", len(blake2b512Sum))
fmt.Println("")
// calculate BLAKE3-256 hash
/*
blake3Hash256 := blake3.Sum256(data)
fmt.Println("blake3Hash256:")
fmt.Println(blake3Hash256)
fmt.Printf("hex: %x\n", blake3Hash256)
fmt.Println("length", len(blake3Hash256))
fmt.Println("")
*/
// calculate BLAKE3-512 hash
/*
blake3Hash512 := blake3.Sum512(data)
fmt.Println("blake3Hash512:")
fmt.Println(blake3Hash512)
fmt.Printf("hex: %x\n", blake3Hash512)
fmt.Println("length", len(blake3Hash512))
*/
}