I complete this RSA formula in Java by using Biginteger and its self-contained functions.
this code first generates a random set of prime number p and q by using the "Security Random()" function and "generateProbablePrime()",
Then calculate the modulus n = q * p and phi(n) = (p -1 )(q - 1).
Then select the public key e which is relative prime to the phi(n), by using the function Biginteger.gcd() = 1
and e is in the interval (0, phi(n)).
Here I randomly initiate a new Biginteger with maxium length equaling phi(n) as the value of the public key, and iterate the value of the public key by checking the condition:
publickey.gcd(phi) == 1, and publickey.compareTo(phi(n)) == -1
Encryption: C = M^e mod n, using the modPow() function to calculate directly
Decryption: M = C^e mod n, using the modPow() function to calculate directly
Signature: S = M^d mod n, using the modPow() function to calculate directly
Verification: M = S^e mod n, using the modPow() function to calculate directly
In the main functioin, I do the double check that using the .equals() to check if the Message M equals what is decrpted and Cipher text C equals what is encrypted