public byte[] getExportData(KgkManager kgkManager) { kgkManager.freshIv2(); kgkManager.freshSalt2(); byte[] kgkBlock = kgkManager.getEncryptedKgk(); Crypter settingsCrypter = this.getSettingsCrypter(kgkManager); byte[] encryptedSettings = settingsCrypter.encrypt(Packer.compress(this.getSettingsAsJSON().toString())); byte[] salt = kgkManager.getKgkCrypterSalt(); byte[] exportData = new byte[1 + salt.length + kgkBlock.length + encryptedSettings.length]; exportData[0] = 0x01; System.arraycopy(salt, 0, exportData, 1, salt.length); System.arraycopy(kgkBlock, 0, exportData, 1 + salt.length, kgkBlock.length); System.arraycopy( encryptedSettings, 0, exportData, 1 + salt.length + kgkBlock.length, encryptedSettings.length); return exportData; }
public void storeLocalSettings(KgkManager kgkManager) { kgkManager.freshSalt2(); kgkManager.freshIv2(); Crypter settingsCrypter = this.getSettingsCrypter(kgkManager); JSONObject storeStructure = new JSONObject(); try { storeStructure.put("settings", this.getSettingsAsJSON()); storeStructure.put("synced", this.getSyncedSettings()); } catch (JSONException jsonError) { Log.d("Settings saving error", "Could not construct JSON structure for storage."); jsonError.printStackTrace(); } SharedPreferences.Editor savedDomainsEditor = savedDomains.edit(); if (settingsCrypter != null) { byte[] encryptedSettings = settingsCrypter.encrypt(Packer.compress(storeStructure.toString())); savedDomainsEditor.putString( "encryptedSettings", Base64.encodeToString(encryptedSettings, Base64.DEFAULT)); savedDomainsEditor.apply(); kgkManager.storeLocalKgkBlock(); } }