Giter Site home page Giter Site logo

stanojevicboban / flutter_secure_storage Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mogol/flutter_secure_storage

0.0 0.0 0.0 26.22 MB

A Flutter plugin to store data in secure storage

Home Page: https://pub.dartlang.org/packages/flutter_secure_storage

Java 15.18% Ruby 2.46% Objective-C 12.42% Dart 28.89% CMake 10.22% C++ 26.66% C 1.63% HTML 2.18% Swift 0.36%

flutter_secure_storage's Introduction

flutter_secure_storage

Important notice for Android and v5.0.0

When upgrading from 4.2.1 to 5.0.0 you can migrate to EncryptedSharedPreferences by setting the encryptedSharedPreference parameter to true as explained below. This will automatically migrate all preferences. This however can't be undone. If you try to disable encryptedSharedPreference after this, you won't be able to read the values. You can only read those with encryptedSharedPreference enabled.

Important notice for Web

flutter_secure_storage only works on HTTPS or localhost environments. Please see this issue for more information.

A Flutter plugin to store data in secure storage:

  • Keychain is used for iOS
  • AES encryption is used for Android. AES secret key is encrypted with RSA and RSA key is stored in KeyStore
  • With v5.0.0 we can use EncryptedSharedPreferences on Android by enabling it in the Android Options like so:
  AndroidOptions _getAndroidOptions() => const AndroidOptions(
        encryptedSharedPreferences: true,
      );

For more information see the example app.

Note KeyStore was introduced in Android 4.3 (API level 18). The plugin wouldn't work for earlier versions.

Platform Implementation

Please note that this table represents the functions implemented in this repository and it is possible that changes haven't yet been released on pub.dev

read write delete containsKey readAll deleteAll
Android
iOS
Windows
Linux
macOS
Web

Getting Started

If not present already, please call WidgetsFlutterBinding.ensureInitialized() in your main before you do anything with the MethodChannel. Please see this issue for more info.

import 'package:flutter_secure_storage/flutter_secure_storage.dart';

// Create storage
final storage = new FlutterSecureStorage();

// Read value
String value = await storage.read(key: key);

// Read all values
Map<String, String> allValues = await storage.readAll();

// Delete value
await storage.delete(key: key);

// Delete all
await storage.deleteAll();

// Write value
await storage.write(key: key, value: value);

This allows us to be able to fetch secure values while the app is backgrounded, by specifying first_unlock or first_unlock_this_device. The default if not specified is unlocked. An example:

final options = IOSOptions(accessibility: IOSAccessibility.first_unlock);
await storage.write(key: key, value: value, iOptions: options);

Configure Android version

In [project]/android/app/build.gradle set minSdkVersion to >= 18.

android {
    ...

    defaultConfig {
        ...
        minSdkVersion 18
        ...
    }

}

Note By default Android backups data on Google Drive. It can cause exception java.security.InvalidKeyException:Failed to unwrap key. You need to

Configure Web Version

Flutter Secure Storage uses an experimental implementation using WebCrypto. Use at your own risk at this time. Feedback welcome to improve it. The intent is that the browser is creating the private key, and as a result, the encrypted strings in local_storage are not portable to other browsers or other machines and will only work on the same domain.

It is VERY important that you have HTTP Strict Forward Secrecy enabled and the proper headers applied to your responses or you could be subject to a javascript hijack.

Please see:

Configure Linux Version

You need libsecret-1-dev and libjsoncpp-dev on your machine to build the project, and libsecret-1-0 and libjsoncpp1 to run the application (add it as a dependency after packaging your app). If you using snapcraft to build the project use the following

parts:
  uet-lms:
    source: .
    plugin: flutter
    flutter-target: lib/main.dart
    build-packages:
      - libsecret-1-dev
      - libjsoncpp-dev
    stage-packages:
      - libsecret-1-dev
      - libjsoncpp-dev

Configure MacOS Version

You also need to add Keychain Sharing as capability to your macOS runner.

Integration Tests

Run the following command from example directory

flutter drive --target=test_driver/app.dart

flutter_secure_storage's People

Contributors

juliansteenbakker avatar mogol avatar talhabalaj avatar kennethnym avatar arok avatar jon-salmon avatar zhenqiu1101 avatar lidongze91 avatar wytesk133 avatar iassal avatar 0biwankenobi avatar pieteraelse avatar mehmetf avatar jthlim avatar hnvn avatar ewertonrp avatar morrica avatar hacker1024 avatar aliaksei-liavonik avatar stevealexander avatar p709723778 avatar koskimas avatar negator avatar nate-eisner avatar mosc avatar michaelrfairhurst avatar maleandr avatar jordylangen avatar hmawla avatar gerritkopp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.