summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-08-14 13:54:43 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-08-14 13:54:43 -0400
commit1ed0e523773ef996693f6f5a7e616da6d4181ca2 (patch)
treeb4f6c45a0af93a0b3cf4095e1532458f5676500f /lib
parentd69a6ca224d807367bbf03bd4507f3d2d7e22caf (diff)
lib: add `TestRSAEncryptDecrypt`
Diffstat (limited to 'lib')
-rw-r--r--lib/rsa_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/rsa_test.go b/lib/rsa_test.go
index f735f75..c0d4ce4 100644
--- a/lib/rsa_test.go
+++ b/lib/rsa_test.go
@@ -136,3 +136,41 @@ func TestRSAGenKey(t *testing.T) {
return
}
}
+
+func TestRSAEncryptDecrypt(t *testing.T) {
+ pair, err := RSAGenKey()
+ if err != nil {
+ t.Errorf("genkey: %v", err)
+ return
+ }
+ pub := pair.Public
+ prv := pair.Private
+
+ // [1] Encrypt.
+ msg := []byte("42")
+ enc := pub.Encrypt(msg)
+ if len(enc) < 1 {
+ t.Errorf("encrypt failed: %v", enc)
+ return
+ }
+ // [1] Decrypt.
+ dec := prv.Decrypt(enc)
+ if !BytesEqual(msg, dec) {
+ t.Errorf("decrypt failed: %v", dec)
+ return
+ }
+
+ // [2] Encrypt.
+ msg = []byte("0xd1a4a6e870b40a261827f17741c19facf80d01a537d55e59abe5d615d961a23f")
+ enc = pub.Encrypt(msg)
+ if len(enc) < 1 {
+ t.Errorf("encrypt failed: %v", enc)
+ return
+ }
+ // [2] Decrypt.
+ dec = prv.Decrypt(enc)
+ if !BytesEqual(msg, dec) {
+ t.Errorf("decrypt failed: %v", dec)
+ return
+ }
+}