Пример #1
0
        public bool SendOpenPortRequest(
            OpenPortRequest request,
            string password)
        {
            var key            = _configuration.LoadPrivateKey(_clientName);
            var requestInBytes = Encoding.UTF8.GetBytes(
                JsonConvert.SerializeObject(request, Formatting.Indented));
            var signature      = Encryptor.Sign(requestInBytes, key, password);
            var dataToTransmit = new TransmissionData(_clientName, requestInBytes, signature);

            var streamToTransmit = Encoding.UTF8.GetBytes(
                JsonConvert.SerializeObject(dataToTransmit, Formatting.Indented));

            OnSendRequest(streamToTransmit);
            return(true);
        }
        public bool SendOpenPortRequest(OpenPortRequest request, string password)
        {
            //ok we will send the request directly encrypting with the password
            var serializedRequest = Encoding.UTF8.GetBytes(
                JsonConvert.SerializeObject(request, Formatting.Indented));

            //need to encrypt with the password, remember also to generate a salt
            //of 8 bytes that will be added to the stream.
            var salt      = EncryptionUtils.GenerateRandomSalt();
            var encrypted = Encryptor.SimmetricEncrypt(password, salt, serializedRequest);

            var ms = new MemoryStream();

            using BinaryWriter sw = new BinaryWriter(ms);

            sw.Write(salt);
            sw.Write(request.PortToOpen);
            sw.Write(encrypted);

            OnSendRequest(ms.ToArray());
            return(true);
        }
 public OpenPortRequestEventArgs(OpenPortRequest request)
 {
     Request = request;
 }