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.8
You can install packages from the command line:
$ flutter packages get
Alternatively, your editor might support
flutter packages get.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
|0.0.8||Sep 10, 2018|
|0.0.7||Aug 28, 2018|
|0.0.6||Aug 21, 2018|
|0.0.5||Aug 5, 2018|
|0.0.4||Jul 31, 2018|
|0.0.3||Jul 30, 2018|
|0.0.2||Apr 12, 2018|
|0.0.1||Mar 20, 2018|
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 Oct 10, 2018, 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.
Maintain an example. (-10 points)
Create a short demo in the
example/ directory to show how to use this package. Common file name patterns include:
example.dart or you could also use
Package is pre-v0.1 release. (-10 points)
While there is nothing inherently wrong with versions of
0.0.*, it usually means that the author is still experimenting with the general direction of the API.