Example #1
0
        public static async void GetKeyData()
        {
            HttpResponseMessage response = await client.GetAsync(CreateQueryString(Properties.Resources.ProjectID, QueryType.Get, "keys", SignInDetails.localId));

            string json = response.Content.ReadAsStringAsync().Result;

            if (response.IsSuccessStatusCode && !(string.IsNullOrEmpty(json) || json == "null"))
            {
                Debug.WriteLine("Successful");
                KeyPairDTO data = JsonConvert.DeserializeObject <KeyPairDTO>(json);
                Keys = new KeyPair(data);
                return;
            }
            else
            {
                //Creates key pair
                KeyPair keys = CreateNewKeySet();
                keys.UserID = SignInDetails.localId;
                KeyPairDTO    dto = new KeyPairDTO(keys);
                Task <string> val = PostData(dto);
                val.Wait();
                if (!string.IsNullOrEmpty(val.Result))
                {
                    Debug.WriteLine("Successful Keys");
                    return;
                }

                Debug.WriteLine("Unsuccessful");
                return;
            }
        }
Example #2
0
        public static async Task <string> PostData(KeyPairDTO dto)
        {
            string data    = JsonConvert.SerializeObject(dto);
            var    content = new StringContent(data, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.PatchAsync(CreateQueryString(Properties.Resources.ProjectID, QueryType.Update, "keys", SignInDetails.localId), content);

            if (response.IsSuccessStatusCode)
            {
                Debug.WriteLine("Successful Key Post");
                string json = response.Content.ReadAsStringAsync().Result;
                Dictionary <string, string> dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
                return(dict.Values.FirstOrDefault());
            }
            else
            {
                Debug.WriteLine("Unsuccessful key post");
                return("");
            }
        }
 public KeyPair(KeyPairDTO dto)
 {
     PrivateKey = dto.PrivateKey.GetParameters(true);
     PublicKey  = dto.PublicKey.GetParameters(false);
 }