Setup Facebook Conceal.
Write string to encrypted file.
// String inputval input = "..."val inputStream = ByteArrayInputStream(input.toByteArray(UTF_8))// create output file in cache directoryval timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd-kkmmss"))val outputFile = File.createTempFile("backup-${timestamp}", null, context.cacheDir);// create Facebook Conceal encrypted output streamval outputStream = App.getCrypto().getCipherOutputStream( outputFile.outputStream(), Entity.create("backup_key"))// write input to output streaminputStream.use { input -> outputStream.use { output -> input.copyTo(output) }}
Read/decrypt input from encrypted file.
val inputFile = File(...)// create Facebook Conceal encrypted input stream from inputFileval inputStream = crypto.getCipherInputStream( inputFile.inputStream(), Entity.create(KEY_BACKUP))// create output stream to read stringval outputStream = ByteArrayOutputStream()// write input to output streaminputStream.use { input -> outputStream.use { output -> input.copyTo(output) }}// convert ByteArrayOutputStream to stringval output = String(outputStream.toByteArray(), Charsets.UTF_8)