示例#1
0
        public RSA(int byteSize, int margin, int threads, int certainty)
        {
            // Choose primes
            BigInteger p = Support.GeneratePrime(threads, byteSize, margin, certainty, provider);
            BigInteger q = Support.GeneratePrime(threads, byteSize, margin, certainty, provider);


            // For optimization
            BigInteger p_1 = p - 1;
            BigInteger q_1 = q - 1;

            // Calculate needed values
            n = p * q;
            BigInteger lcm = (p_1 * q_1) / Support.GCD(p_1, q_1);

            // Generate e such that is is less than and coprime to lcm
            do
            {
                e = RandomSupport.GenerateBoundedRandom(lcm, provider);
            } while (e == lcm || Support.GCD(e, lcm) != 1);

            // Generate the modular multiplicative inverse
            d          = Support.Dio(e, lcm).Key + lcm;
            CanEncrypt = true;
            CanDecrypt = true;
        }