-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencryption_test.go
More file actions
66 lines (60 loc) · 1.62 KB
/
encryption_test.go
File metadata and controls
66 lines (60 loc) · 1.62 KB
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
package goencryption
import (
"fmt"
"testing"
)
func TestEasyEncrypt(t *testing.T) {
des := map[string]string{
"key": "12345678",
"data": "12345678abcdefgh",
"iv": "---><---",
}
triDes := map[string]string{
"key": "123456781234567812345678",
"data": "12345678abcdefgh",
"iv": "(----)->",
}
aes := map[string]string{
"key": "12345678123456781234567812345678",
"data": "12345678abcdefgh",
"iv": "<------><------>",
}
cryptoType := []string{"aes", "des", "3des"}
mode := []string{"ECB", "CBC", "CFB", "OFB", "CTR"}
padding := []string{"No","Zero", "Pkcs5", "Pkcs7"}
transcode := []string{"Base64", "Hex"}
for _, cv := range cryptoType {
var d map[string]string
switch cv {
case "aes":
d = aes
case "des":
d = des
case "3des":
d = triDes
}
for _, mv := range mode {
for _, pv := range padding {
if cv=="aes" && pv=="Pkcs5"{
continue // The block size of AES is 16, and the complement length needs to be 16, while the length of PKCS5 is 8
}
for _, tv := range transcode {
fmt.Println(cv+"/"+mv+"/"+pv+"/"+tv)
desSource, err := EasyEncrypt(cv+"/"+mv+"/"+pv+"/"+tv, d["data"], d["key"], d["iv"])
if err != nil {
t.Fatal(err,cv+"/"+mv+"/"+pv+"/"+tv, d["data"], d["key"], d["iv"])
}
data, err := EasyDecrypt(cv+"/"+mv+"/"+pv+"/"+tv, desSource, d["key"], d["iv"])
if err != nil {
t.Fatal(err)
}
if data != d["data"] {
t.Fatalf("EasyEncrypt is faile,\n" +
"cv:%s ,mv:%s,pv:%s,tv%s,data:%s,key:%s,iv:%s \n" +
"want %x, got %x", cv,mv,pv,tv, d["data"], d["key"], d["iv"],d["data"], data)
}
}
}
}
}
}