public void Init(SerialNumbersSettings.ProtectedApp app) { string pubKey; switch (app) { case SerialNumbersSettings.ProtectedApp.SecureMemo: pubKey = SerialNumbersSettings.ProtectedApplications.PublicKeys.SecureMemo; break; case SerialNumbersSettings.ProtectedApp.SearchForDuplicates: pubKey = SerialNumbersSettings.ProtectedApplications.PublicKeys.SearchForDuplicates; break; default: throw new ArgumentOutOfRangeException("app"); } RSA_AsymetricEncryption rsaAsymetricEncryption = new RSA_AsymetricEncryption(); RSAKeySetIdentity rsaPublicKeySetIdentity = new RSAKeySetIdentity("", pubKey); RSAParameters rsaPublicKey = rsaAsymetricEncryption.ParseRSAPublicKeyOnlyInfo(rsaPublicKeySetIdentity); _serialNumberManager = new SerialNumberManager(rsaPublicKey, app); }
public async Task <SecureChatUser> RegisterNewUser(SecureChatCreateUserRequest userRequest, RSAKeySetIdentity keySetIdentity) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(HostNameURL); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.PostAsJsonAsync("api/securechat/users", userRequest); if (response.IsSuccessStatusCode) { // Get the URI of the created resource. string responceMessage = await response.Content.ReadAsStringAsync(); StringReader sr = new StringReader(responceMessage); JsonReader jsonReader = new JsonTextReader(sr); CreateNewUser createNewUserServerResponce = _jsonSerializer.Deserialize <CreateNewUser>(jsonReader); RSA_AsymetricEncryption rsaAsymetricEncryption = new RSA_AsymetricEncryption(); RSAParameters rsaParameters = rsaAsymetricEncryption.ParseRSAPublicKeyOnlyInfo(keySetIdentity); string aesKey = rsaAsymetricEncryption.DecryptObjectUsingRSA(createNewUserServerResponce.EncodedAESKey, rsaParameters); // Todo decrypt incoming data using AES SecureChatUser secureChatUser = new SecureChatUser(); //register public key //PublicKeyData publicKeyData = new PublicKeyData(); //publicKeyData.GUID = userKeySet.RSA_GUID; //publicKeyData.PublicKey = userKeySet.RSA_PublicKey; //response = await client.PostAsJsonAsync("api/securechat/publickeys", publicKeyData); if (response.IsSuccessStatusCode) { return(secureChatUser); } } } return(null); }