From d69a6ca224d807367bbf03bd4507f3d2d7e22caf Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Sun, 14 Aug 2022 13:54:25 -0400 Subject: lib: RSAPrivate: add `Decrypt` --- lib/rsa.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib') 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() +} -- cgit v1.2.3