forked from Versent/unicreds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryptor_test.go
39 lines (27 loc) · 890 Bytes
/
encryptor_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
package unicreds
import (
"crypto/rand"
"testing"
"github.com/stretchr/testify/assert"
)
var (
dataKey = []byte{0x6a, 0xcf, 0xeb, 0xd6, 0xe9, 0xa6, 0x19, 0xc1, 0x38, 0xb9, 0xfc, 0x2d, 0x53, 0x23, 0x4d, 0x78, 0x85, 0x48, 0x96, 0xd6, 0xd2, 0xf6, 0xf4, 0x42, 0x99, 0x9d, 0x8e, 0xa9, 0xed, 0xf0, 0xb3, 0xf2}
cipherText = []byte{0xa3, 0xcc, 0x1e, 0xd7, 0x3a, 0xfd, 0x18, 0x3f, 0x8a, 0xb2, 0xd5, 0x6f, 0xdf, 0x1d, 0x98, 0x4d, 0xe4, 0xf6}
)
func TestEncrypt(t *testing.T) {
plaintext := []byte("something test 123")
cdata, err := Encrypt(dataKey, plaintext)
assert.Nil(t, err)
assert.Equal(t, cdata, cipherText)
}
func TestDecrypt(t *testing.T) {
plaintext := []byte("something test 123")
cdata, err := Decrypt(dataKey, cipherText)
assert.Nil(t, err)
assert.Equal(t, cdata, plaintext)
}
func readRandData(c int) []byte {
b := make([]byte, c)
rand.Read(b)
return b
}