-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoaep_test.go
61 lines (50 loc) · 1.14 KB
/
oaep_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
61
package oaep
import (
"bytes"
"crypto/rand"
"crypto/rsa"
"testing"
"github.com/ssh-vault/crypto"
)
func TestOAEP(t *testing.T) {
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
t.Error(err)
}
publicKey := &privateKey.PublicKey
message := []byte("The quick brown fox jumps over the lazy dog")
ciphertext, err := Encrypt(publicKey, message, []byte(""))
if err != nil {
t.Error(err)
}
plaintext, err := Decrypt(privateKey, ciphertext, []byte(""))
if err != nil {
t.Error(err)
}
if !bytes.Equal(message, plaintext) {
t.Error("message != plaintext")
}
}
func TestOAEPLabel(t *testing.T) {
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
t.Error(err)
}
publicKey := &privateKey.PublicKey
message := []byte("The quick brown fox jumps over the lazy dog")
label, err := crypto.GenerateNonce(64)
if err != nil {
t.Error(err)
}
ciphertext, err := Encrypt(publicKey, message, label)
if err != nil {
t.Error(err)
}
plaintext, err := Decrypt(privateKey, ciphertext, label)
if err != nil {
t.Error(err)
}
if !bytes.Equal(message, plaintext) {
t.Error("message != plaintext")
}
}