encryptFile static method
Encrypt the file at args1 using the password at args2.
The encrypted content is saved to a new file with _enc suffix.
The original file remains unchanged.
The encryption uses SecureCompressor from secure_compressor package.
The output file is named ORIGINAL_NAME_enc.txt in the current directory.
Implementation
static Future<void> encryptFile(
String path,
String password, {
encriptor.AESMode mode = encriptor.AESMode.sic,
}) async {
final file = File(path);
if (!file.existsSync()) {
print("❌ File not found: $path");
return;
}
final data = await file.readAsString();
final encrypted = encrypt(data, password, mode: mode);
final filename = path.split(Platform.pathSeparator).last;
final extIndex = filename.lastIndexOf(".");
final base = extIndex == -1 ? filename : filename.substring(0, extIndex);
final outFile = File("${Directory.current.path}${Platform.pathSeparator}${base}_enc.txt");
await outFile.writeAsString(encrypted);
print("✅ Encrypted -> ${outFile.path}");
}