private void storeKeyPair(ECKeyPair keyPair) {
    String privateKey = CMAccountUtils.encodeHex(keyPair.getPrivateKey().getD());
    ECPoint publicKey = keyPair.getPublicKey().getQ();

    ContentValues values = new ContentValues();
    values.put(CMAccountProvider.ECDHKeyStoreColumns.PRIVATE, privateKey.toString());
    values.put(
        CMAccountProvider.ECDHKeyStoreColumns.PUBLIC,
        CMAccountUtils.encodeHex(publicKey.getEncoded()));
    values.put(CMAccountProvider.ECDHKeyStoreColumns.KEY_ID, keyPair.getKeyId());
    mContext.getContentResolver().insert(CMAccountProvider.ECDH_CONTENT_URI, values);
  }
  private void removePublicKeys(AddPublicKeysResponse response) {
    List<ECKeyPair> keyPairs = getKeyPairs();
    for (ECKeyPair keyPair : keyPairs) {
      String keyId = keyPair.getKeyId();
      if (!response.getKeyIds().contains(keyId)) {
        if (CMAccount.DEBUG) Log.d(TAG, "Removing public key_id " + keyId);
        String selection = CMAccountProvider.ECDHKeyStoreColumns.KEY_ID + " = ?";
        String[] selectionArgs = new String[] {keyId};
        mContext
            .getContentResolver()
            .delete(CMAccountProvider.ECDH_CONTENT_URI, selection, selectionArgs);
      }
    }

    // If after removing public keys, we are left with no keys, generate some more.
    if (getKeyCount() < MINIMUM_KEYS) {
      if (CMAccount.DEBUG)
        Log.d(TAG, "Left without enough keys after removing stale keys, generating more.");
      start(mIntent);
    }
  }