From eee7a6af613b7d4c7cb4b8333d1f5ecf30236301 Mon Sep 17 00:00:00 2001
From: siddharth ravikumar <s@ricketyspace.net>
Date: Sun, 14 Aug 2022 13:54:05 -0400
Subject: lib: RSAPub: add `Encrypt`

---
 lib/rsa.go | 11 +++++++++++
 1 file changed, 11 insertions(+)

(limited to 'lib')

diff --git a/lib/rsa.go b/lib/rsa.go
index 17cf6b0..00d575e 100644
--- a/lib/rsa.go
+++ b/lib/rsa.go
@@ -175,3 +175,14 @@ func RSAGenKey() (*RSAPair, error) {
 
 	return pair, nil
 }
+
+func (r *RSAPub) Encrypt(msg []byte) []byte {
+	// Convert message to big int.
+	m := big.NewInt(0).SetBytes(msg)
+
+	// Encrypt.
+	c := big.NewInt(0).Exp(m, r.e, r.n)
+
+	return c.Bytes()
+}
+
-- 
cgit v1.2.3