summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-08-14 13:54:25 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-08-14 13:54:25 -0400
commitd69a6ca224d807367bbf03bd4507f3d2d7e22caf (patch)
treed599f5e51508555fb754426f0e46c53b4d2e34ab /lib
parenteee7a6af613b7d4c7cb4b8333d1f5ecf30236301 (diff)
lib: RSAPrivate: add `Decrypt`
Diffstat (limited to 'lib')
-rw-r--r--lib/rsa.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/rsa.go b/lib/rsa.go
index 00d575e..3d29bae 100644
--- a/lib/rsa.go
+++ b/lib/rsa.go
@@ -186,3 +186,12 @@ func (r *RSAPub) Encrypt(msg []byte) []byte {
return c.Bytes()
}
+func (r *RSAPrivate) Decrypt(cipher []byte) []byte {
+ // Convert cipher to big int.
+ c := big.NewInt(0).SetBytes(cipher)
+
+ // Decrypt.
+ m := big.NewInt(0).Exp(c, r.d, r.n)
+
+ return m.Bytes()
+}