-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypter_test.go
60 lines (55 loc) · 1.13 KB
/
encrypter_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
package crypto
import (
"bytes"
"fmt"
"testing"
)
var (
testEncrypterKey = []byte("secret-key-secret-key-secret-key")
testEncrypterPlaintext = []byte("foobar")
)
func TestEncrypter(t *testing.T) {
e, err := NewEncrypter(testEncrypterKey)
if err != nil {
panic(err)
}
b, err := e.Encrypt([]byte(testEncrypterPlaintext))
if err != nil {
panic(err)
}
b, err = e.Decrypt(b)
if err != nil {
panic(err)
}
if !bytes.Equal(testEncrypterPlaintext, b) {
t.Errorf("encode/decode: want %s, got %s", testEncrypterPlaintext, b)
}
}
func TestEncrypterBase64(t *testing.T) {
e, err := NewEncrypter(testEncrypterKey)
if err != nil {
panic(err)
}
b, err := e.EncryptBase64(testEncrypterPlaintext)
if err != nil {
panic(err)
}
fmt.Println(string(b))
b, err = e.DecryptBase64(b)
if err != nil {
panic(err)
}
if !bytes.Equal(testEncrypterPlaintext, b) {
t.Errorf("encode/decode base64: want %s, got %s", testEncrypterPlaintext, b)
}
}
func TestHashHS256(t *testing.T) {
e, err := NewEncrypter(testEncrypterKey)
if err != nil {
panic(err)
}
_, err = e.HashHS256(testEncrypterPlaintext)
if err != nil {
panic(err)
}
}