-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_test.go
151 lines (114 loc) · 3.43 KB
/
utils_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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package go_authcode
import (
"fmt"
//"time"
"testing"
)
func TestHan(t *testing.T) {
fmt.Println("abc是汉字吗:",IsChineseChar("abc"))
fmt.Println("哎哎哎是汉字吗:",IsChineseChar("哎哎哎"))
}
func TestBase64_Bytes2Bytes(t *testing.T) {
bRaw :=[]byte{0x01,0x02,0x03,0x04}
fmt.Println("BRAW:",bRaw)
if en,err :=Base64_Bytes2Bytes(BASE64_ENCODE,bRaw);err ==nil{
fmt.Println("ENCODE:",en)
if de,err :=Base64_Bytes2Bytes(BASE64_DECODE,en);err ==nil{
fmt.Println("DECODE:",de)
}else{
fmt.Println("DECODE fail,err=",err)
}
}else{
fmt.Println("ENCODE fail,err=",err)
}
}
func TestBase64_string2Bytes(t *testing.T) {
sRaw :="abcdeflg"
fmt.Println("SRAW:",sRaw)
if en,err :=Base64_String2Bytes(BASE64_ENCODE,sRaw);err ==nil{
fmt.Println("ENCODE:",en)
if de,err :=Base64_String2Bytes(BASE64_DECODE,string(en));err ==nil{
fmt.Println("DECODE:",string(de))
}else{
fmt.Println("DECODE fail,err=",err)
}
}else{
fmt.Println("ENCODE fail,err=",err)
}
}
func TestBase64_Bytes2String(t *testing.T) {
bRaw :=[]byte{0x01,0x02,0x03,0x04,0x05,0x06}
fmt.Println("bRAW:",bRaw)
if en,err :=Base64_Bytes2String(BASE64_ENCODE,bRaw);err ==nil{
fmt.Println("ENCODE:",en)
if de,err :=Base64_Bytes2String(BASE64_DECODE,[]byte(en));err ==nil{
fmt.Println("DECODE:",[]byte(de))
}else{
fmt.Println("DECODE fail,err=",err)
}
}else{
fmt.Println("ENCODE fail,err=",err)
}
}
func TestBase64_String2String(t *testing.T) {
sRaw :="/+abcdeflg/+"
fmt.Println("sRAW:",sRaw)
if en,err :=Base64_String2String(BASE64_ENCODE,sRaw);err ==nil{
fmt.Println("ENCODE:",en)
if de,err :=Base64_String2String(BASE64_DECODE,en);err ==nil{
fmt.Println("DECODE:",de)
}else{
fmt.Println("DECODE fail,err=",err)
}
}else{
fmt.Println("ENCODE fail,err=",err)
}
}
func TestBase64_WEB_String2String(t *testing.T) {
sRaw :="/+abcdeflg/+"
fmt.Println("sRAW:",sRaw)
if en,err :=Base64_WEB_String2String(BASE64_ENCODE,sRaw);err ==nil{
fmt.Println("ENCODE:",en)
if de,err :=Base64_WEB_String2String(BASE64_DECODE,en);err ==nil{
fmt.Println("DECODE:",de)
}else{
fmt.Println("DECODE fail,err=",err)
}
}else{
fmt.Println("ENCODE fail,err=",err)
}
}
func TestBase64_WEB_Bytes2Bytes(t *testing.T) {
bRaw :=[]byte("/+abcdeflg/+")
fmt.Println("bRAW:",bRaw)
if en,err :=Base64_WEB_Bytes2Bytes(BASE64_ENCODE,bRaw);err ==nil{
fmt.Println("ENCODE:",en)
if de,err :=Base64_WEB_Bytes2Bytes(BASE64_DECODE,en);err ==nil{
fmt.Println("DECODE:",de)
}else{
fmt.Println("DECODE fail,err=",err)
}
}else{
fmt.Println("ENCODE fail,err=",err)
}
}
//测试结果可知,对于authcode,hex字符串形式的32位字符串才具有真正的使用价值
//因为keya与keyb以及很多其他细节都是基于32位字符串切割的,而不是基于16位字符串或者16位字节序列
func TestMd5(t *testing.T){
bRaw :=[]byte{0x01,0x02,0x03}
fmt.Println(Md5_Bytes2Bytes(bRaw),"len is:",len(Md5_Bytes2Bytes(bRaw)))
fmt.Println(Md5_Bytes2Hexstring(bRaw),"len is:",len(Md5_Bytes2Hexstring(bRaw)))
sRaw :=string(bRaw)
fmt.Println(Md5_String2Hexstring(sRaw),"len is:",len(Md5_String2Hexstring(sRaw)))
}
func TestKeyDynamic(t *testing.T){
keyDynamic :=make([]byte,8)
keyDynamic =nil
keyA :=[]byte{0x01,0x02,0x03}
keyB := append([]byte{},keyDynamic...)
keyC := append(keyA,keyDynamic...)
fmt.Println("keyB:",keyB)
fmt.Println("keyC:",keyC)
fmt.Println("keyA:",keyA[:0])
fmt.Println("keyA:",keyA[2:])
}