-
Notifications
You must be signed in to change notification settings - Fork 48
/
3des_test.go
executable file
·55 lines (46 loc) · 1.47 KB
/
3des_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
package openssl
import (
"encoding/base64"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDes3Encrypt(t *testing.T) {
src := []byte("123456")
// 3DES-ECB, PKCS7_PADDING
key := []byte("123456789012345678901234")
dst, err := Des3ECBEncrypt(src, key, PKCS7_PADDING)
assert.NoError(t, err)
t.Log(base64.StdEncoding.EncodeToString(dst))
assert.Equal(t, base64.StdEncoding.EncodeToString(dst), "zvq8DAMSQaM=")
}
func TestDes3ECBDecrypt(t *testing.T) {
src, err := base64.StdEncoding.DecodeString("zvq8DAMSQaM=")
assert.NoError(t, err)
// 3DES-ECB, PKCS7_PADDING
key := []byte("123456789012345678901234")
dst, err := Des3ECBDecrypt(src, key, PKCS7_PADDING)
assert.NoError(t, err)
t.Log(string(dst))
assert.Equal(t, dst, []byte("123456"))
}
func TestDes3CBCEncrypt(t *testing.T) {
src := []byte("123456")
iv := []byte("67890678")
// 3DES-ECB, PKCS7_PADDING
key := []byte("123456789012345678901234")
dst, err := Des3CBCEncrypt(src, key, iv, PKCS7_PADDING)
assert.NoError(t, err)
t.Log(base64.StdEncoding.EncodeToString(dst))
assert.Equal(t, base64.StdEncoding.EncodeToString(dst), "elcFR372FXU=")
}
func TestDes3CBCDecrypt(t *testing.T) {
src, err := base64.StdEncoding.DecodeString("elcFR372FXU=")
assert.NoError(t, err)
iv := []byte("67890678")
// 3DES-ECB, PKCS7_PADDING
key := []byte("123456789012345678901234")
dst, err := Des3CBCDecrypt(src, key, iv, PKCS7_PADDING)
assert.NoError(t, err)
t.Log(string(dst))
assert.Equal(t, dst, []byte("123456"))
}