file_encrypter 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

File Encrypter #

pub package

Super fast file encrypter for flutter. Uses AES-256 in CBC mode with PKCS5 padding.

Supports large files too.

Supports Android Only for now. Will be working for iOS soon (Contribution is will appreciated).

Usage #

For Encryption:

String secretKey = await FileEncrypter.encrypt(
    inFilename: 'open_file.mkv',
    outFileName: 'encrypted_file.dat',
); // key is base64 encoded secret key (PRNG generated).

//Creates `encryted_file.dat`, which is encrypted version of `open_file.mkv`.

For Decryption:

String key = await FileEncrypter.decrypt(
    key: secretKey, // secretKey from above
    inFilename: 'encrypted_file.dat',
    outFileName: 'open_file.mkv',
);

//Creates `open_file.mkv`, which is decrypted version of `encrypted_file.dat`.

License #

Copyright 2020 Sarbagya Dhaubanjar. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.
    * Neither the name of Google Inc. nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

1.0.1 #

  • (Improvement) Run encryption/decryption off the Main thread

1.0.0 #

  • Initial Release

example/lib/main.dart

import 'package:file_encrypter/file_encrypter.dart';
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:path_provider/path_provider.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'My App',
      home: EncryptApp(),
    );
  }
}

String key;

class EncryptApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            RaisedButton.icon(
              onPressed: () async {
                final path = '${(await getApplicationSupportDirectory()).path}/sarbagya.p.download';
                try {
                  await Dio().download(
                    'http://25.io/toau/audio/sample.txt',
                    path,
                    onReceiveProgress: (s, t) {
                      print((s / t).toStringAsFixed(2));
                    },
                    options: Options(receiveTimeout: 0, followRedirects: true, receiveDataWhenStatusError: true),
                  );
                } catch (e) {
                  print(e);
                }
                key = await FileEncrypter.encrypt(
                  inFilename: '${(await getApplicationSupportDirectory()).path}/sarbagya.p.download',
                  outFileName: '${(await getApplicationSupportDirectory()).path}/sarbagya.dat',
                );
                print('Encryption Ended');
              },
              icon: Icon(Icons.cloud_download),
              label: Text('Download & Encrypt'),
            ),
            RaisedButton.icon(
              onPressed: () async {
                await FileEncrypter.decrypt(
                  key: key,
                  inFilename: '${(await getApplicationSupportDirectory()).path}/sarbagya.dat',
                  outFileName: '${(await getApplicationSupportDirectory()).path}/podcast.dat',
                );
                print('Decryption Ended');
              },
              icon: Icon(Icons.cloud_download),
              label: Text('Decrypt'),
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  file_encrypter: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:file_encrypter/file_encrypter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
46
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:file_encrypter/file_encrypter.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:file_encrypter/file_encrypter.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:file_encrypter/file_encrypter.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:file_encrypter/file_encrypter.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • file_encrypter that is a package requiring null.

Maintenance issues and suggestions

Repository URL doesn't exist. (-10 points)

At the time of the analysis the repository field https://github.com/sarbagyastha/file_encrypter was unreachable.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
meta >=1.1.8 <2.0.0 1.1.8 1.2.2
Transitive dependencies
collection 1.14.12 1.14.13
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test