saveEncryptedData static method

Future<void> saveEncryptedData(
  1. String content,
  2. String passphrase
)

Save encrypted content to file

Implementation

static Future<void> saveEncryptedData(String content, String passphrase) async {
  final salt = _generateSalt();
  final iv = _generateIV();
  final key = await _deriveKey(passphrase, salt);
  final encrypted = await _encrypt(content, key, iv);

  final payload = jsonEncode({
    'salt': base64Encode(salt),
    'iv': base64Encode(iv),
    'data': base64Encode(encrypted),
  });

  final filePath = await _getPublicDocumentsPath();
  final file = File(filePath);
  await file.writeAsString(payload);
}