예제 #1
0
        protected override bool HandshakePassive(SendCall Send, ReceiveCall Receive)
        {
            if (!Receive(out byte[] data, out EndPoint source))
            {
                return(false);
            }

            KEXCrypto.FromXmlString(Encoding.ASCII.GetString(data));


            byte[] key = new byte[32];
            RandomNumberGenerator.Create().GetBytes(key);

            DataCrypto.Key = key;
            Send(KEXCrypto.Encrypt(key, RSAEncryptionPadding.OaepSHA256));

            if (!Receive(out data, out source))
            {
                return(false);
            }

            DataCrypto.IV = data;
            Send(EncryptData(SECRET));

            return(true);
        }
예제 #2
0
 public bool Handshake(SendCall Send, ReceiveCall Receive)
 {
     if (Active)
     {
         return(HandshakeActive(Send, Receive));
     }
     else
     {
         return(HandshakePassive(Send, Receive));
     }
 }
예제 #3
0
        protected override bool HandshakeActive(SendCall Send, ReceiveCall Receive)
        {
            Send(KEXCrypto.GetPublicKey());
            if (!Receive(out byte[] data, out EndPoint source))
            {
                return(false);
            }

            DataCrypto.Key = KEXCrypto.GetSharedSecret(data);
            Send(DataCrypto.IV);

            if (!Receive(out data, out source))
            {
                return(false);
            }

            return(DecryptSecret(data));
        }
예제 #4
0
        protected override bool HandshakeActive(SendCall Send, ReceiveCall Receive)
        {
            Send(Encoding.ASCII.GetBytes(KEXCrypto.ToXmlString(false)));
            if (!Receive(out byte[] data, out EndPoint source))
            {
                return(false);
            }

            DataCrypto.Key = KEXCrypto.Decrypt(data, RSAEncryptionPadding.OaepSHA256);
            Send(DataCrypto.IV);

            if (!Receive(out data, out source))
            {
                return(false);
            }

            return(DecryptSecret(data));
        }
예제 #5
0
        protected override bool HandshakeActive(SendCall Send, ReceiveCall Receive)
        {
            Send(KEXCrypto.PublicKey.ToByteArray());
            if (!Receive(out byte[] data, out EndPoint source))
            {
                return(false);
            }

            DataCrypto.Key = KEXCrypto.DeriveKeyMaterial(CngKey.Import(data, CngKeyBlobFormat.EccPublicBlob));
            Send(DataCrypto.IV);

            if (!Receive(out data, out source))
            {
                return(false);
            }

            return(DecryptSecret(data));
        }
예제 #6
0
        protected override bool HandshakePassive(SendCall Send, ReceiveCall Receive)
        {
            if (!Receive(out byte[] data, out EndPoint source))
            {
                return(false);
            }

            DataCrypto.Key = KEXCrypto.GetSharedSecret(data);
            Send(KEXCrypto.GetPublicKey());

            if (!Receive(out data, out source))
            {
                return(false);
            }

            DataCrypto.IV = data;
            Send(EncryptData(SECRET));

            return(true);
        }
예제 #7
0
        protected override bool HandshakePassive(SendCall Send, ReceiveCall Receive)
        {
            if (!Receive(out byte[] data, out EndPoint source))
            {
                return(false);
            }

            DataCrypto.Key = KEXCrypto.DeriveKeyMaterial(CngKey.Import(data, CngKeyBlobFormat.EccPublicBlob));
            Send(KEXCrypto.PublicKey.ToByteArray());

            if (!Receive(out data, out source))
            {
                return(false);
            }

            DataCrypto.IV = data;
            Send(EncryptData(SECRET));

            return(true);
        }
예제 #8
0
 protected abstract bool HandshakePassive(SendCall Send, ReceiveCall Receive);
예제 #9
0
 protected override bool HandshakePassive(SendCall Send, ReceiveCall Receive)
 {
     return(true);
 }