public async Task <bool> Save(PublicKeyDto dto) { var ps = Session.Prepare("insert into mob_users_keys (mob_user_id, device_type, public_key) values (?, ? , ?)"); var statement = ps.Bind(dto.EnduserId, dto.DeviceType, dto.PublicKeyBase64String); await Session.ExecuteAsync(statement); return(true); }
public static void FormatHkpPublicKey(StringBuilder buffer, PublicKeyDto key) { buffer.AppendLine(key.ToString("HKP")); foreach (var identity in key.KeyIdentities) { buffer.AppendLine(identity.ToString("HKP")); } }
public async Task Post([FromBody] PublicKeyDto requestDto) { if (String.IsNullOrWhiteSpace(requestDto.EnduserId) || String.IsNullOrWhiteSpace(requestDto.DeviceType.ToString()) || String.IsNullOrWhiteSpace(requestDto.PublicKeyBase64String)) { throw new ArgumentException("Invalid request"); } await _publicKeyRepo.Save(requestDto); }
public IHttpActionResult PublicKeyDistribution() { PublicKeyDto publicKeyDto = new PublicKeyDto { PublicKeyBase = KEYBASE, PublicKeyModulo = KEYMODULO }; return(Ok(publicKeyDto)); }
private async Task PublishPublicKey(string key) { var toPost = new PublicKeyDto { EnduserId = "yusbel_gmail_Android_TD_Spend", DeviceType = DeviceType.AndroidPhone.ToString(), PublicKeyBase64String = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(key)) }; var client = new HttpClient(); var jsonToPost = JsonConvert.SerializeObject(toPost); var content = new StringContent(jsonToPost, Encoding.UTF8, "application/json"); var result = await client.PostAsync(new Uri($"{BaseMobileSecurity}/api/UserKey"), content); }
public void Given_User_and_DeviceType_Then_SaveKey() { //arrange var rsaProvider = new RSACryptoServiceProvider(2048); var publicKey = rsaProvider.PublicKeyToXmlString(); var toPost = new PublicKeyDto { EnduserId = "yusbel_gmail_com_Android_TD_Spend", DeviceType = DeviceType.AndroidPhone.ToString(), PublicKeyBase64String = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(publicKey)) }; //act var client = new HttpClient(); var jsonToPost = JsonConvert.SerializeObject(toPost); var content = new StringContent(jsonToPost, Encoding.UTF8, "application/json"); var result = client.PostAsync(new Uri($"{BaseMobileSecurity}/api/UserKey"), content).Result; //assert Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(result.IsSuccessStatusCode); }