-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdes_test.go
92 lines (85 loc) · 2.25 KB
/
des_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
package goencryption
import (
"reflect"
"testing"
)
var (
testKey = []byte("12345678")
testData = []byte("123abc1234567abcdefg")
testIv = []byte("---><---")
)
func TestDesECB(t *testing.T) {
dst, err := DesECBPkcs7Encrypt(testAesData, testKey)
if err != nil {
t.Errorf("DesECBPkcs7Encrypt() error = %v", err)
return
}
src, err := DesECBPkcs7Decrypt(dst, testKey)
if err != nil {
t.Errorf("DesECBPkcs7Decrypt() error = %v", err)
return
}
if !reflect.DeepEqual(src, testAesData) {
t.Errorf("DesCBCPkcs7Encrypt() got = %v, want %v", src, testAesData)
}
}
func TestDesCBC(t *testing.T) {
dst, err := DesCBCPkcs7Encrypt(testAesData, testKey, testIv)
if err != nil {
t.Errorf("DesCBCPkcs7Encrypt() error = %v", err)
return
}
src, err := DescCBCPkcs7Decrypt(dst, testKey, testIv)
if err != nil {
t.Errorf("DescCBCPkcs7Decrypt() error = %v", err)
return
}
if !reflect.DeepEqual(src, testAesData) {
t.Errorf("DesCBCPkcs7Encrypt() got = %v, want %v", src, testAesData)
}
}
func TestDesCFB(t *testing.T) {
dst, err := DesCFBPkcs7Encrypt(testAesData, testKey, testIv)
if err != nil {
t.Errorf("DesCFBPkcs7Encrypt() error = %v", err)
return
}
src, err := DesCFBPkcs7Decrypt(dst, testKey, testIv)
if err != nil {
t.Errorf("DesCFBPkcs7Decrypt() error = %v", err)
return
}
if !reflect.DeepEqual(src, testAesData) {
t.Errorf("DesCBCPkcs7Encrypt() got = %v, want %v", src, testAesData)
}
}
func TestDesOFB(t *testing.T) {
dst, err := DesOFBPkcs7Encrypt(testAesData, testKey, testIv)
if err != nil {
t.Errorf("DesOFBPkcs7Encrypt() error = %v", err)
return
}
src, err := DesOFBPkcs7Decrypt(dst, testKey, testIv)
if err != nil {
t.Errorf("DesOFBPkcs7Decrypt() error = %v", err)
return
}
if !reflect.DeepEqual(src, testAesData) {
t.Errorf("DesCBCPkcs7Encrypt() got = %v, want %v", src, testAesData)
}
}
func TestDesCTR(t *testing.T) {
dst, err := DesCTRPkcs7Encrypt(testAesData, testKey, testIv)
if err != nil {
t.Errorf("DesCTRPkcs7Encrypt() error = %v", err)
return
}
src, err := DesCTRPkcs7Decrypt(dst, testKey, testIv)
if err != nil {
t.Errorf("DesCTRPkcs7Decrypt() error = %v", err)
return
}
if !reflect.DeepEqual(src, testAesData) {
t.Errorf("DesCBCPkcs7Encrypt() got = %v, want %v", src, testAesData)
}
}