mod n maps to Modulus , p -1 mod q maps to InverseQ , the encryption metric is mapped to Exponent , and the decryption metric is mapped to D
The encryption index e and decryption index D are associated with e * d = 1 mod (p-1) (q-1). That way, if you have them, you can easily get another use of several methods from the System.Numerics.BigInteger class.
var Pminus1 = BigInteger.Subtract(P, BigInteger.One); var Qminus1 = BigInteger.Subtract(Q, BigInteger.One); var Phi = BigInteger.Multiply(Pminus1, Qminus1); var PhiMinus1 = BigInteger.Subtract(Phi, BigInteger.One);
Note that you must be careful when creating the .NET BigInteger, especially if you are used to the Java BigInteger class. See this question for more information.
EDIT:
Because CodeInChaos indicates that the last line is WRONG!
WRONG! WRONG! WRONG!
I am embarrassed. In bowing to the forces of evil, the BigInteger class does not have a modular inverse method or an extended Euclidean algorithm method. However, you can use google for the 'C # advanced Euclidean algorithm, you can find many implementations. The extended Euclidean algorithm will give you integers x and y such that 1 = e * x + phi * y. x is the inverse of e mod phi, so you need to set D = x mod phi.
source share