private JSONObject encrypt(JSONObject plain) {
    JSONObject result = null;
    try {
      result = Utils.encrypt(plain, preparePublicKey.get());
    } catch (InterruptedException | ExecutionException e) {
      e.printStackTrace();
    }

    return result;
  }
  private void handleResponse(JSONObject response) throws Exception {

    if ("{}".equals(response.toString())) { // no session is open
      throw new Exception("aasdgasg");
    }

    browserId = Utils.jsonObjectGetString(response, "browser_id");
    sessionID = Utils.jsonObjectGetString(response, "id");

    Browser browser = databaseHelper.getBrowser(browserId);

    // preload public key
    preparePublicKey = new PreparePublicKey();
    preparePublicKey.execute(browser);

    JSONObject encryptedMessage = Utils.jsonObjectGetJSONObject(response, "message");

    if ("{}".equals(encryptedMessage.toString())) {
      throw new Exception("aasdgasg");
    }

    JSONObject message =
        Utils.getJSONObject(Utils.decrypt(encryptedMessage, browser.getMy_private_key()));

    Logger.log("Received", message.toString());

    location = Utils.jsonObjectGetString(message, "location");
    domain = Utils.jsonObjectGetString(message, "domain");
    title = Utils.jsonObjectGetString(message, "title");
    username = Utils.jsonObjectGetString(message, "username");
    passwordString = Utils.jsonObjectGetString(message, "password");
    elementId = Utils.jsonObjectGetString(message, "element_id");
    elementName = Utils.jsonObjectGetString(message, "element_name");

    Logger.log("search by domain", domain);

    password = databaseHelper.getPasswordByDomain(domain);

    setContentView(R.layout.activity_login);

    if (password == null) { // no password is known for the domain

      Logger.log("register", "register");

      TextView loginTitle = (TextView) findViewById(R.id.login_title);
      loginTitle.setText(domain);
      ((Button) findViewById(R.id.button_allow)).setText(R.string.allow_and_save);
      findViewById(R.id.edit).setVisibility(View.VISIBLE);

      updateUsernamePassword(username, passwordString);

      EditText passwordField = (EditText) findViewById(R.id.password);
      passwordField.setOnFocusChangeListener(
          new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
              if (!hasFocus) {
                hideKeyboard(v);
              }
            }
          });

    } else {
      Logger.log("login", "login");

      TextView loginTitle = (TextView) findViewById(R.id.login_title);
      loginTitle.setText(domain);

      updateUsernamePassword(
          password.getValue(Password.KEY_USERNAME), password.getValue(Password.KEY_PASSWORD));
    }
  }