Пример #1
0
 /// <summary>
 /// Generates the key after a response is received.
 /// </summary>
 /// <param name="response">The string representation of the response.</param>
 public void HandleResponse(PayloadReader pr)
 {
     // Get the response and modpow it with the stored prime.
     using (BigInteger given = pr.ReadBigInteger())
         using (BigInteger key = given.modPow(mine, prime))
         {
             this.key = key.getBytes();
         }
     Dispose();
 }
Пример #2
0
        /// <summary>
        /// Generate a response packet.
        /// </summary>
        /// <param name="request">The string representation of the request.</param>
        /// <returns></returns>
        public DiffieHellman GenerateResponse(PayloadReader pr)
        {
            // Generate the would-be fields.
            using (BigInteger prime = pr.ReadBigInteger())
                using (BigInteger g = pr.ReadBigInteger())
                    using (BigInteger mine = BigInteger.genPseudoPrime(bits, 30, random))
                    {
                        // Generate the key.
                        using (BigInteger given = pr.ReadBigInteger())
                            using (BigInteger key = given.modPow(mine, prime))
                            {
                                this.key = key.getBytes();
                            }
                        // Generate the response.
                        using (BigInteger send = g.modPow(mine, prime))
                        {
                            PayloadWriter pw = new PayloadWriter();
                            pw.WriteBigInteger(send);
                            this.representation = pw.ToByteArray();
                        }
                    }

            return(this);
        }