-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathencryption_test.go
74 lines (71 loc) · 1.59 KB
/
encryption_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
package ravepay
import (
"testing"
)
func Test_getEncryptionKey(t *testing.T) {
tests := []struct {
name string
seckey string
want string
}{
{
name: "return empty if string is empty",
},
{
name: "return empty if string is less than 12",
seckey: "1234567",
},
{
name: "returns the expected encryption key - 1",
seckey: "FLWSECK-bb971402072265fb156e90a3578fe5e6-X",
want: "bb9714020722eb4cf7a169f2",
},
{
name: "returns the expected encryption key - 2",
seckey: "FLWSECK-6b32914d4d60c10d0ef72bdad734134a-X",
want: "6b32914d4d60cb85d8eb73db",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getEncryptionKey(tt.seckey); got != tt.want {
t.Errorf("getKey() = %v, want %v", got, tt.want)
}
})
}
}
func Test_tripleDESEncrypt(t *testing.T) {
type args struct {
payload []byte
key []byte
}
tests := []struct {
name string
args args
want string
}{
{
name: "returns the expected 3DES encrypted payload - 1",
args: args{
payload: []byte("A 16 byte string"),
key: []byte("6b32914d4d60cb85d8eb73db"),
},
want: "9fx+9uGjG+Oikq8syKpfeg==",
},
{
name: "returns the expected 3DES encrypted payload - 2",
args: args{
payload: []byte("Hello world"),
key: []byte("bb9714020722eb4cf7a169f2"),
},
want: "Lgk7z/IvTT9mx3t9vOzHmg==",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tripleDESEncrypt(tt.args.payload, tt.args.key); got != tt.want {
t.Errorf("tripleDESEncrypt() = %v, want %v", got, tt.want)
}
})
}
}