Ejemplo n.º 1
0
        public async Task <string> GetUser(string line)
        {
            var request  = new HttpRequestMessage(HttpMethod.Get, $"user/new?username={line}");
            var response = await _sender.SendAsync(request);

            var product = await _sender.GetResponseString(response);

            return(product);
        }
Ejemplo n.º 2
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);
        }
Ejemplo 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);
        }
        private async Task <string> Decrypt(HttpResponseMessage response, Aes aes)
        {
            var encryptedHex = await _sender.GetResponseString(response);

            var encryptedBytes = encryptedHex.HexToByte();

            return(CryptoHelper.AesDecrypt(encryptedBytes, aes.Key, aes.IV));
        }