decryptTextFromFile method
Decrypts a plain text from srcFilePath
file asynchronously.
If BOM (Byte Order Mark) is present in decrypted data, interprets the data
in accordance with BOM. Otherwise the interpretation will depend on utf16
and endian
arguments.
If the argument utf16
is set to true
, decrypted data will be interpreted
as a list of UTF-16 bytes. Endianness depends on endian
argument.
Otherwise the data will be interpreted as a list of UTF-8 bytes.
Returns Future<String> that completes with decrypted text once the entire operation has completed.
Implementation
Future<String> decryptTextFromFile(String srcFilePath,
{bool utf16 = false, Endian endian = Endian.big}) async {
Uint8List decData = await decryptDataFromFileSync(srcFilePath);
String srcString;
if ((decData[0] == 0xFE && decData[1] == 0xFF) ||
(decData[0] == 0xFF && decData[1] == 0xFE)) {
srcString = decData.toUtf16String();
} else if (decData[0] == 0xEF && decData[1] == 0xBB && decData[2] == 0xBF) {
srcString = decData.toUtf8String();
} else {
srcString =
utf16 ? decData.toUtf16String(endian) : decData.toUtf8String();
}
return srcString;
}