In your flutter project add the dependency:
dependencies: ... flutter_sodium: any
Important: For iOS you'll need to manually update the Podfile in your ios project.
import 'package:flutter_sodium/flutter_sodium.dart'; // Password hashing (using Argon) final password = 'my password'; final str = await PasswordHash.hashStorage(password); print(str); // verify hash str final valid = await PasswordHash.verifyStorage(str, password); assert(valid);
This project includes an extensive example app with runnable code samples. Be sure to check it out!
The flutter_sodium plugin implements the following libsodium APIs *):
*) Some APIs are not available on Android. See this issue for details.
The plugin includes a core API that maps native libsodium functions 1:1 to Dart equivalents. The core API is available in the class
Sodium. Dart naming conventions are used for core API function names. A native libsodium function such as
crypto_pwhash_str, is available in flutter as
Also included in flutter_sodium is a high-level, opinionated API providing access to libsodium in a Dart friendly manner. The various functions are available in separate Dart classes. Password hashing for example is available in the
PasswordHash class. The high-level API depends on the core API to get things done.
The flutter_sodium APIs can be executed on the UI thread, or on a background thread. Most crypto tasks can safely run on the UI thread, some tasks take considerable time to execute (most notable crypto_pwhash_* ), and will run on a background thread by default. All methods of the core API includes an optional
useBackgroundThread argument to switch from UI to background thread or vice versa. Background execution is implemented using
AsyncTask in Android, and
DispatchQueue in iOS.
Please note that the entire API is asynchronous. Even when a crypto task is executed on the UI thread, the method returns an async
Future which needs to be awaited.
Add this to your package's pubspec.yaml file:
dependencies: flutter_sodium: ^0.0.10
You can install packages from the command line:
$ flutter pub get
Alternatively, your editor might support
flutter pub get.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
We analyzed this package on Aug 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
flutter format to format
Maintain an example. (-10 points)
Create a short demo in the
example/ directory to show how to use this package.
Common filename patterns include
flutter_sodium.dart. Packages with multiple examples should provide
For more information see the pub package layout conventions.
Package is pre-v0.1 release. (-10 points)
While nothing is inherently wrong with versions of
0.0.*, it might mean that the author is still experimenting with the general direction of the API.