Reputation: 27
I am having issues decryption in my code where the values I get from encryption and decryption aren't matching and the value of decryption is always the value of 1. I have attached all my code and would love some help in why this is happening as it has dazzled me a bit.
Upvotes: 1
Views: 115
Reputation: 41958
The line
d = (BigInteger.valueOf(1).mod(phi).divide(e)); //check with nick
is incorrect, as I'm sure Nick will confirm. You need to compute the modular inverse of e mod phi. In Java this is available as BigInteger.modInverse(..)
, so the correct line would be
d = e.modInverse(phi);
Upvotes: 1