Exemple #1
0
        public HKeyExchange(BigInteger PublicExponent, BigInteger PublicModulus, BigInteger PrivateExponent, int BitSize = 16)
        {
            this.BitSize = BitSize;
            IsInitiator  = (PrivateExponent != null);
            RSA          = new RSAKey(PublicExponent, PublicModulus, PrivateExponent);

            if (IsInitiator)
            {
                do
                {
                    DHPrime = BigInteger.genPseudoPrime(212, 6, ByteGen);
                }while (!DHPrime.isProbablePrime());

                do
                {
                    DHGenerator = BigInteger.genPseudoPrime(212, 6, ByteGen);
                }while (DHGenerator == DHPrime || !DHPrime.isProbablePrime());

                if (DHGenerator > DHPrime)
                {
                    BigInteger DHGenShell = DHGenerator;
                    DHGenerator = DHPrime;
                    DHPrime     = DHGenShell;
                }

                DHPrivate = new BigInteger(RandomHex(30), BitSize);
                DHPublic  = DHGenerator.modPow(DHPrivate, DHPrime);
            }
        }
Exemple #2
0
 public HKeyExchange(RSAKey Keys, int BitSize = 16)
     : this(Keys.e, Keys.n, Keys.d, BitSize)
 {
 }