summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-08-14 13:54:05 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-08-14 13:54:05 -0400
commiteee7a6af613b7d4c7cb4b8333d1f5ecf30236301 (patch)
treeb62380be7024c31c46da5d45a83f88b12ad35d9b /lib
parent3aadff0d4782858afb687593ba54a6066467c95d (diff)
lib: RSAPub: add `Encrypt`
Diffstat (limited to 'lib')
-rw-r--r--lib/rsa.go11
1 files changed, 11 insertions, 0 deletions
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()
+}
+