Exemplo n.º 1
0
        /*
         * This is realy dummy contructor that need only
         * for one reason : calculating difference between
         * async constructor and sync constructor
         */
        private RSACryptor(int bitLength, RSAInstanceType type)
        {
            if (bitLength <= 0)
            {
                throw new Exception("all is really bad");
            }

            if (type == RSAInstanceType.Sync)
            {
                keyLength = bitLength;
                PrimeNumberRandomizer rand = new PrimeNumberRandomizer();

                q = rand.GetRandom(keyLength);
                p = rand.GetRandom(keyLength);

                while (q == p)
                {
                    q = rand.GetRandom(keyLength);
                }

                n = p * q;
                eulerFunctionValue = (p - 1) * (q - 1);

                e = GenerateE(keyLength);
                d = GenerateD(eulerFunctionValue, e);
            }
        }
Exemplo n.º 2
0
        /*
         * This constructor generate all numbers that RSA needs
         * Take care this function may throw exception
         */
        public RSACryptor(int bitlength)
        {
            if (bitlength <= 0)
            {
                throw new Exception("all is really bad");
            }

            keyLength = bitlength;

            PrimeNumberRandomizer rand = new PrimeNumberRandomizer();

            Task calculateQTask = new Task(() => q = rand.GetRandom(keyLength));
            Task calculatePTask = new Task(() => p = rand.GetRandom(keyLength));

            calculateQTask.Start();
            calculatePTask.Start();
            calculateQTask.Wait();
            calculatePTask.Wait();

            while (q == p)
            {
                q = rand.GetRandom(keyLength);
            }

            n = p * q;
            eulerFunctionValue = (p - 1) * (q - 1);

            e = GenerateE(keyLength);
            d = GenerateD(eulerFunctionValue, e);
        }
Exemplo n.º 3
0
        /*
         * Generate e(open exponent) for RSA
         */
        private BigInteger GenerateE(int keyLength)
        {
            int eBitLength               = keyLength / 3;
            PrimeNumberRandomizer rand   = new PrimeNumberRandomizer();
            BigInteger            result = rand.GetRandom(eBitLength);

            return(result);
        }