-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.go
52 lines (41 loc) · 1.23 KB
/
test.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
package main
import (
"encoding/json"
"fmt"
"go-zero-websocket/common/util"
)
type ConnectDecode struct {
Ws string
Web string
}
func main() {
key := []byte("QHO871N859CJDL0CJ5Q08CJM3S1Q6S6M")
iv := []byte("7QMH21TN8KPMG75G")
fmt.Println("哎哟不错哦:", string(key[12:20]), string(iv[4:12]))
desTest(key, iv)
aesTest(key, iv)
}
func desTest(key, iv []byte) {
connData := map[string]string{
"nickname": "12",
"userid": "75",
"product": "go-zero-im",
}
marshal, _ := json.Marshal(connData)
encrypt := util.DesEncrypt(marshal, key, iv, false)
fmt.Println("des加密结果:" + string(encrypt))
decode := util.DesDecrypt(encrypt, key, iv, false)
fmt.Println("des解密结果:" + string(decode))
fmt.Println("----------------------------------------")
}
func aesTest(key, iv []byte) {
str := []byte("[{\"title\":\"\",\"username\":\"\"}]")
encrypt := util.AesEncrypt(str, key, iv)
fmt.Println("aes加密结果:" + string(encrypt))
decrypt := util.AesDecrypt(encrypt, key, iv)
fmt.Println("aes解密结果:" + string(decrypt))
var cDecode []ConnectDecode
_ = json.Unmarshal(decrypt, &cDecode)
fmt.Printf("解析成结构体:%s \n", cDecode[0])
fmt.Println("----------------------------------------")
}