encryptFile method

Future<String> encryptFile(
  1. String srcFilePath, [
  2. String destFilePath = ''
])

Encrypts srcFilePath file to destFilePath file asynchronously.

If the argument destFilePath is not specified, encrypted file name is created as a concatenation of srcFilePath and '.aes' file extension.

If encrypted file exists, the behaviour depends on AesCryptOwMode.

Returns Future<String> that completes with the path to encrypted file once the entire operation has completed.

Implementation

Future<String> encryptFile(String srcFilePath,
    [String destFilePath = '']) async {
  srcFilePath = srcFilePath.trim();
  destFilePath = destFilePath.trim();
  AesCryptArgumentError.checkNullOrEmpty(_password, 'Empty password.');
  AesCryptArgumentError.checkNullOrEmpty(
      srcFilePath, 'Empty source file path.');
  if (srcFilePath == destFilePath) {
    throw AesCryptArgumentError(
        'Source file path and encrypted file path are the same.');
  }
  return await _Cryptor.init(_passBytes, _owMode, _userdata)
      .encryptFile(srcFilePath, destFilePath);
}