forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aes_test.go
37 lines (28 loc) · 864 Bytes
/
aes_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
package crypto
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou"
)
func TestBase64AES(t *testing.T) {
originalText := "encrypt this golang"
key := []byte("example key 1234")
// encrypt value to base64
cryptoText, err := Base64AESEncode(key, originalText)
if err != nil {
t.Fatal(err)
}
// encrypt base64 crypto to original value
text, err := Base64AESDecode(key, cryptoText)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "encrypt this golang", text)
}
func TestBase64AESProcess(t *testing.T) {
args := []interface{}{"example key 1234", "encrypt this golang"}
cryptoText := gou.NewProcess("yao.crypto.AESBase64Encode", args...).Run()
args = []interface{}{"example key 1234", cryptoText}
text := gou.NewProcess("yao.crypto.AESBase64Decode", args...).Run()
assert.Equal(t, "encrypt this golang", text)
}