...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package darwin
15
16 import (
17 "bytes"
18 "crypto"
19 "crypto/rsa"
20 "testing"
21 )
22
23 const testIssuer = "TestIssuer"
24
25 func TestClientEncrypt(t *testing.T) {
26 secureKey, err := NewSecureKey(testIssuer)
27 if err != nil {
28 t.Errorf("Cred: got %v, want nil err", err)
29 return
30 }
31 plaintext := []byte("Plain text to encrypt")
32 _, err = secureKey.Encrypt(nil, plaintext, crypto.SHA256)
33 if err != nil {
34 t.Errorf("Client API encryption: got %v, want nil err", err)
35 return
36 }
37 }
38
39 func TestClientDecrypt(t *testing.T) {
40 secureKey, err := NewSecureKey(testIssuer)
41 if err != nil {
42 t.Errorf("Cred: got %v, want nil err", err)
43 return
44 }
45 byteSlice := []byte("Plain text to encrypt")
46 ciphertext, _ := secureKey.Encrypt(nil, byteSlice, crypto.SHA256)
47 plaintext, err := secureKey.Decrypt(nil, ciphertext, &rsa.OAEPOptions{Hash: crypto.SHA256})
48 if err != nil {
49 t.Errorf("Client API decryption: got %v, want nil err", err)
50 return
51 }
52 if !bytes.Equal(byteSlice, plaintext) {
53 t.Errorf("Decryption message does not match original: got %v, want %v", plaintext, byteSlice)
54 }
55 }
56
View as plain text