Esempio n. 1
0
        public string ProtectedHello()
        {
            if (!_sender.UserCheck())
            {
                return("");
            }
            var request  = new HttpRequestMessage(HttpMethod.Get, "protected/hello");
            var response = _sender.SendAuthenticatedAsync(request).Result;

            return(_sender.GetResponseString(response).Result);
        }
Esempio n. 2
0
        public async Task DeleteUser()
        {
            if (!_sender.UserCheck())
            {
                return;
            }

            var request  = new HttpRequestMessage(HttpMethod.Delete, $"user/removeuser?username={_sender.UserHandler.Value.Username}");
            var response = await _sender.SendAuthenticatedAsync(request);

            var product = await _sender.GetResponseString(response);

            var success = Convert.ToBoolean(product);

            _output.Log(success.ToString());
        }
Esempio n. 3
0
        public async Task Process(string value)
        {
            if (!HasKey())
            {
                return;
            }

            if (!_sender.UserCheck())
            {
                return;
            }

            var request  = new HttpRequestMessage(HttpMethod.Get, $"protected/sign?message={value}");
            var response = _sender.SendAuthenticatedAsync(request);

            // Hash while waiting for server response
            var hashedValue = Hash(value);

            // Convert hex string to byte array;
            var hexadecimal = await _sender.GetResponseString(await response);

            var  signatureHash  = CryptoHelper.HexToByte(hexadecimal);
            bool validSignature = VerifyHash(hashedValue, signatureHash);

            string outcome = validSignature
                ? "Message was successfully signed"
                : "Message was not successfully signed";

            _output.Log(outcome);
        }
        public async Task Process(int value)
        {
            //TODO change value to int and allow auto converter to handle.
            if (!HasKey())
            {
                return;
            }

            using Aes aes = Aes.Create();
            var request = GenerateWebRequest(value, aes);
            HttpResponseMessage response = await _sender.SendAuthenticatedAsync(request);

            if (response.StatusCode is not HttpStatusCode.OK)
            {
                _output.Log("An error occurred!", LogType.Warning);
                return;
            }

            string decrypted = await Decrypt(response, aes);

            _output.Print(decrypted);
        }