flutter_sodium 0.0.2

  • README.md
  • Example
  • Installing
  • Versions
  • 57


With flutter_sodium you get access to the modern, easy-to-use libsodium crypto library in your Flutter apps. One set of crypto APIs supporting both Android and iOS.

API coverage

At this point in time flutter_sodium implements the following high-level libsodium APIs:

  • crypto_auth
  • crypto_box
  • crypto_generichash
  • crypto_kdf
  • crypto_kx
  • crypto_onetimeauth
  • crypto_pwhash
  • crypto_scalarmult
  • crypto_secretbox
  • crypto_shorthash
  • crypto_sign
  • randombytes
  • sodium_version


  1. A core API that maps 1:1 to libsodium functions. Should cover the entire high-level API.
  2. Proper argument checks
  3. Fix missing API functions (such as crypto_pwhash_str_needs_rehash)
  4. A Dart-friendly, opinionated API wrapping the core API. Should work with types other than Uint8List such as strings, streams, etc.

Getting Started

In your flutter project add the dependency:

  flutter_sodium: any

Usage example

import 'package:flutter_sodium/flutter_sodium.dart';

// Password hashing (using Argon)
const opslimit = crypto_pwhash_OPSLIMIT_INTERACTIVE;
const memlimit = crypto_pwhash_MEMLIMIT_INTERACTIVE;
final password = utf8.encode('my password');
final str = await Sodium.cryptoPwhashStr(password, opslimit, memlimit);

print('Password hash str: ${ascii.decode(str)}');

// verify hash str
final valid = await Sodium.cryptoPwhashStrVerify(str, password);


Current issues

  • Some APIs are not available yet in Android
  • Getting a Swift plugin to work nicely with Flutter on iOS is a painful operation. See als https://github.com/flutter/flutter/issues/16049
  • Since Flutter does not support native binaries (see also https://github.com/flutter/flutter/issues/7053), a platform channel is established to enable native function invocation. One side effect of this approach is that the entire flutter_sodium API is asynchronous. This is great for potential long-running operations such as Argon password hashing, but does not make much sense for other short-running functions.

[0.0.2] - April 12, 2018

  • Adds support for Flutter Beta 2 and Dart 2

[0.0.1] - March 20, 2018

  • Initial release with core libsodium API support.


import 'package:flutter/material.dart';
import 'examples.dart';
import 'package:flutter_sodium/flutter_sodium.dart';

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

class MyApp extends StatelessWidget {
  runExamples() async {
    final version = await Sodium.sodiumVersionString();

    print('Sodium $version');

    await exampleCryptoAuth();
    await exampleCryptoBox();
    await exampleCryptoBoxDetached();
    await exampleCryptoBoxPrecalculated();
    await exampleCryptoBoxPrecalculatedDetached();
    await exampleCryptoBoxSeal();
    await exampleCryptoGenerichash();
    await exampleCryptoGenericHashNoKey();
    await exampleCryptoGenerichashMultiPart();
    await exampleCryptoKdf();
    await exampleCryptoKx();
    await exampleCryptoOnetimeauth();
    await exampleCryptoOnetimeauthMultiPart();
    await exampleCryptoPwhash();
    await exampleCryptoPwhashStr();
    await exampleCryptoScalarmult();
    await exampleCryptoSecretbox();
    await exampleCryptoSecretboxDetached();
    await exampleCryptoShorthash();
    await exampleCryptoSign();
    await exampleCryptoSignDetached();
    await exampleCryptoSignMultiPart();
    await exampleRandombytes();

    print('Examples completed');

  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: new Text('Flutter Sodium'),
          body: new Center(
              child: new RaisedButton(
                  child: new Text('Run samples'), onPressed: runExamples))),

1. Depend on it

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

  flutter_sodium: "^0.0.2"

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_sodium/flutter_sodium.dart';
Version Uploaded Documentation Archive
0.0.2 Apr 12, 2018 Go to the documentation of flutter_sodium 0.0.2 Download flutter_sodium 0.0.2 archive
0.0.1 Mar 20, 2018 Go to the documentation of flutter_sodium 0.0.1 Download flutter_sodium 0.0.1 archive


We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6
  • Flutter: 0.3.2


Describes how popular the package is relative to other packages. [more]
15 / 100
Code health derived from static analysis. [more]
100 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 2 hints.

    Run flutter format to format lib/flutter_sodium.dart.

    Run flutter format to format lib/src/constants.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <2.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.9
meta 1.1.2
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6