Skip to content

Instantly share code, notes, and snippets.

@vadv
Created July 1, 2017 15:42
Show Gist options
  • Save vadv/5622bb061df5ff4c29a82126dda9c31a to your computer and use it in GitHub Desktop.
Save vadv/5622bb061df5ff4c29a82126dda9c31a to your computer and use it in GitHub Desktop.
func RSA_public_decrypt(pubKey *rsa.PublicKey, data []byte) []byte {
c := new(big.Int)
m := new(big.Int)
m.SetBytes(data)
e := big.NewInt(int64(pubKey.E))
c.Exp(m, e, pubKey.N)
out := c.Bytes()
skip := 0
for i := 2; i < len(out); i++ {
if i+1 >= len(out) {
break
}
if out[i] == 0xff && out[i+1] == 0 {
skip = i + 2
break
}
}
return out[skip:]
}
@iyusa
Copy link

iyusa commented Dec 14, 2021

is there RSA_public_encrypt?

@vincentkenny
Copy link

nice work. Works like a charm for me. thanks a lot 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment