Esempio n. 1
0
        public RSAKey GenerateKey()
        {
            BigInteger first  = generator.FindPrime();
            BigInteger second = generator.FindPrime();

            // BigInteger first = 17;
            // BigInteger second = 11;

            while (first == second)
            {
                second = generator.FindPrime();
            }

            BigInteger n   = (first * second);
            BigInteger phi = (first - 1) * (second - 1);
            BigInteger e   = generator.FindCoPrime(phi);
            BigInteger d   = modInverse(e, phi);

            key   = new RSAKey();
            key.n = n;
            key.e = e;
            key.d = d;

            Console.WriteLine("first: " + first);
            Console.WriteLine("second: " + second);
            Console.WriteLine("pxq: " + n);
            Console.WriteLine("(p-1)x(q-1): " + phi);
            Console.WriteLine("e: " + e);
            Console.WriteLine("d: " + d);

            return(key);
        }
Esempio n. 2
0
 public RSA(RSAKey key)
 {
     this.key = key;
 }