Пример #1
0
 public Bob(Tuple <BigInteger, BigInteger> primes, BigInteger publicKey)
 {
     P_G        = primes;
     PrivateKey = DiffieHellman.PrivateKey(P_G.Item1);
     PublicKey  = DiffieHellman.PublicKey(P_G.Item1, P_G.Item2, PrivateKey);
     if (publicKey != null)
     {
         Key = DiffieHellman.Secret(P_G.Item1, publicKey, PrivateKey);
     }
 }
Пример #2
0
        public CNG B(CNG c)
        {
            c.Alice.P_G      = c.Bob.P_G = DiffieHellman.GetTwoCryptoPrimes();
            c.Bob.PrivateKey = DiffieHellman.PrivateKey(c.Bob.P_G.Item1);
            c.Bob.PublicKey  = DiffieHellman.PublicKey(c.Bob.P_G.Item1, c.Bob.P_G.Item2, c.Bob.PrivateKey);
            if (c.Alice.PublicKey != null)
            {
                c.Bob.Key = c.Alice.Key = DiffieHellman.Secret(c.Bob.P_G.Item1, c.Alice.PublicKey, c.Bob.PrivateKey);
            }


            return(c);
        }
Пример #3
0
        public CNG A(CNG c)
        {
            //alice creates a public and private key
            c.Alice.P_G        = c.Bob.P_G = DiffieHellman.GetTwoCryptoPrimes();
            c.Alice.PrivateKey = DiffieHellman.PrivateKey(c.Alice.P_G.Item1);
            c.Alice.PublicKey  = DiffieHellman.PublicKey(c.Alice.P_G.Item1, c.Alice.P_G.Item2, c.Alice.PrivateKey);
            //check if bob has supplied public key yet
            if (c.Bob.PublicKey != null)
            {
                c.Bob.Key = c.Alice.Key = DiffieHellman.Secret(c.Alice.P_G.Item1, c.Bob.PublicKey, c.Alice.PrivateKey);
            }

            return(c);
        }
Пример #4
0
 public bool MakeKey(BigInteger publicKey)
 {
     try
     {
         PrivateKey = DiffieHellman.PrivateKey(P_G.Item1);
         PublicKey  = DiffieHellman.PublicKey(P_G.Item1, P_G.Item2, PrivateKey);
         //check if bob has supplied public key yet
         if (publicKey != null)
         {
             Key = DiffieHellman.Secret(P_G.Item1, publicKey, PrivateKey);
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }