forked from micro/go-micro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypto_test.go
41 lines (33 loc) · 839 Bytes
/
crypto_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
package tunnel
import (
"bytes"
"testing"
)
func TestEncrypt(t *testing.T) {
key := "tokenpassphrase"
data := []byte("supersecret")
cipherText, err := Encrypt(data, key)
if err != nil {
t.Errorf("failed to encrypt data: %v", err)
}
// verify the cipherText is not the same as data
if bytes.Equal(data, cipherText) {
t.Error("encrypted data are the same as plaintext")
}
}
func TestDecrypt(t *testing.T) {
key := "tokenpassphrase"
data := []byte("supersecret")
cipherText, err := Encrypt(data, key)
if err != nil {
t.Errorf("failed to encrypt data: %v", err)
}
plainText, err := Decrypt(cipherText, key)
if err != nil {
t.Errorf("failed to decrypt data: %v", err)
}
// verify the plainText is the same as data
if !bytes.Equal(data, plainText) {
t.Error("decrypted data not the same as plaintext")
}
}