Beispiel #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);
            }
        }
 public override byte[] ToBytes()
 {
     return(TLUtils.Combine(
                TLUtils.SignatureToBytes(Signature),
                Nonce.ToBytes(),
                ServerNonce.ToBytes(),
                G.ToBytes(),
                DHPrime.ToBytes(),
                GA.ToBytes(),
                ServerTime.ToBytes()));
 }