How to Perform File encryption with Flutter and Dart


I don't know if it is right to ask my question here. I just need to make a feasibility study for an App I am trying to build. I chose Flutter because I allow to quickly create mobile apps.

My application will be storing voice messages in forms of audio files. It can be an mp3 or an audio format.

To make it readable by the receiver only, I need to encrypt the file using may be AES or e2e encryption.

I need to know if it is possible to encrypt files with Dart in my flutter app. If it is possible, I would like to get useful resources.

I tried to search for this topic, but I can only find articles about encrypting string or text files.


Finally found something. I tried multiple options including the encrypt package, but all were dead ends. I finally found this package It can encrypt files using AES all you need is the path to the file. It is well documented. I believe its best to create a class and add functions for encrypt and decrypt as I have did below.

import 'dart:io'; import 'package:aes_crypt/aes_crypt.dart'; class EncryptData { static String encrypt_file(String path) { AesCrypt crypt = AesCrypt(); crypt.setOverwriteMode(AesCryptOwMode.on); crypt.setPassword('my cool password'); String encFilepath; try { encFilepath = crypt.encryptFileSync(path); print('The encryption has been completed successfully.'); print('Encrypted file: $encFilepath'); } catch (e) { if (e.type == AesCryptExceptionType.destFileExists) { print('The encryption has been completed unsuccessfully.'); print(e.message); } else{ return 'ERROR'; } } return encFilepath; } static String decrypt_file(String path) { AesCrypt crypt = AesCrypt(); crypt.setOverwriteMode(AesCryptOwMode.on); crypt.setPassword('my cool password'); String decFilepath; try { decFilepath = crypt.decryptFileSync(path); print('The decryption has been completed successfully.'); print('Decrypted file 1: $decFilepath'); print('File content: ' + File(decFilepath).path); } catch (e) { if (e.type == AesCryptExceptionType.destFileExists) { print('The decryption has been completed unsuccessfully.'); print(e.message); } else{ return 'ERROR'; } } return decFilepath; } }

Now you can use it like

encrypted_file_path = EncryptData.encrypt_file('your/file/path');



  • How to expose/access a data store like Redux within a cypress test?
  • npm “operation not permitted”
  • Fixing malformed HTML in PHP?
  • ARKit 2 - Crop Recognizing Images
  • VBA: Choosing Specific Tab on Internet Explorer
  • Audio and video conference with NodeJS
  • Reduce the memory used loading huge pandas dataframe from MongoDB
  • Objective-C version of PHP mcrypt_encrypt
  • Redirecting the print output to a .txt file in Python
  • Parallel exact matrix diagonalization with Python
  • Play Store In-App Billing custom price programmatically?
  • Sending Objects over Java Socket really slow
  • Create my own classList object when the browser does not implement it itself
  • How to integrate Dialogflow with Django (Python)?
  • Optimization of Neural Network input data
  • Haskell function that outputs all combinations within the input list that add to the input number
  • Parsing a complicated array with GetJSON Jquery
  • Google Geocoding API limit exceeded on cell network, but not on wifi
  • Threads and Concurrent Modification Exception working with a list
  • In metro, get all inherited classes of an (abstract) class?
  • Django REST framework - HyperlinkedRelatedField with additional parameter
  • Authorize Attribute Authentication with Postman in Web Api
  • How to use Typescript with libraries like Ampersand.js that parse configs to build prototypes
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • Multiplying polynomials/simplifying like terms
  • Create an average of multiple excel chart without the data source
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • how to run ejabberd with Erlang on Heroku?
  • How to use Streams api peek() function and make it work?
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • Make checkout phone field optional for specific countries in WooCommerce
  • calling IO Operations from thread in ruby c extension will cause ruby to hang
  • Angular 4: Responsive Grid List
  • Write to .csv file with PHP (Commas in Data Error)