Esempio n. 1
0
        private void Initialize(bool ignoreBaseKeys = false)
        {
            PublicKey = 0;

            Random rand = new Random();

            while (PublicKey == 0)
            {
                if (!ignoreBaseKeys)
                {
                    Prime     = PrimeCalculator.GenPseudoPrime(Bitlength, 10, rand);
                    Generator = PrimeCalculator.GenPseudoPrime(Bitlength, 10, rand);
                }

                byte[] bytes = new byte[Bitlength / 8];
                Randomizer.NextBytes(bytes);
                _privateKey = new BigInteger(bytes);

                if (_privateKey < 1)
                {
                    continue;
                }

                if (Generator > Prime)
                {
                    BigInteger temp = Prime;
                    Prime     = Generator;
                    Generator = temp;
                }

                PublicKey = BigInteger.ModPow(Generator, _privateKey, Prime);

                if (!ignoreBaseKeys)
                {
                    break;
                }
            }
        }