All Projects → firstfloorsoftware → Flutter_sodium

firstfloorsoftware / Flutter_sodium

Licence: bsd-3-clause
Flutter bindings for libsodium

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Flutter sodium

Node Sodium
Port of the lib sodium encryption library to Node.js
Stars: ✭ 346 (+349.35%)
Mutual labels:  libsodium
Pynacl
Python binding to the Networking and Cryptography (NaCl) library
Stars: ✭ 761 (+888.31%)
Mutual labels:  libsodium
Wire Webapp
👽 Wire for web
Stars: ✭ 982 (+1175.32%)
Mutual labels:  libsodium
Airship
Secure Content Management for the Modern Web - "The sky is only the beginning"
Stars: ✭ 422 (+448.05%)
Mutual labels:  libsodium
Libsodium.js
libsodium compiled to Webassembly and pure JavaScript, with convenient wrappers.
Stars: ✭ 665 (+763.64%)
Mutual labels:  libsodium
Halite
High-level cryptography interface powered by libsodium
Stars: ✭ 933 (+1111.69%)
Mutual labels:  libsodium
vtun
A mirror of VTUN, with some changes
Stars: ✭ 56 (-27.27%)
Mutual labels:  libsodium
Tweetnacl Js
Port of TweetNaCl cryptographic library to JavaScript
Stars: ✭ 1,176 (+1427.27%)
Mutual labels:  libsodium
Sodium compat
Pure PHP polyfill for ext/sodium
Stars: ✭ 736 (+855.84%)
Mutual labels:  libsodium
Nim Libsodium
Nim wrapper for the libsodium library
Stars: ✭ 32 (-58.44%)
Mutual labels:  libsodium
Libsodium Php
The PHP extension for libsodium.
Stars: ✭ 507 (+558.44%)
Mutual labels:  libsodium
Sodiumoxide
Sodium Oxide: Fast cryptographic library for Rust (bindings to libsodium)
Stars: ✭ 596 (+674.03%)
Mutual labels:  libsodium
Lockbox
Modern encryption for Ruby and Rails
Stars: ✭ 905 (+1075.32%)
Mutual labels:  libsodium
Swift Sodium
Safe and easy to use crypto for iOS and macOS
Stars: ✭ 400 (+419.48%)
Mutual labels:  libsodium
Paseto.rb
Ruby implementation of Paseto using libsodium.
Stars: ✭ 41 (-46.75%)
Mutual labels:  libsodium
Sapient
Secure API Toolkit
Stars: ✭ 308 (+300%)
Mutual labels:  libsodium
Globaleaks
GlobaLeaks is free, open source software enabling anyone to easily set up and maintain a secure whistleblowing platform.
Stars: ✭ 832 (+980.52%)
Mutual labels:  libsodium
Zbox
Zero-details, privacy-focused in-app file system.
Stars: ✭ 1,185 (+1438.96%)
Mutual labels:  libsodium
Lazysodium Android
An Android implementation of the Libsodium cryptography library. For the lazy dev.
Stars: ✭ 69 (-10.39%)
Mutual labels:  libsodium
Rbnacl
Ruby FFI binding to the Networking and Cryptography (NaCl) library (a.k.a. libsodium)
Stars: ✭ 910 (+1081.82%)
Mutual labels:  libsodium

flutter_sodium

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.

Pub

Getting Started

In your flutter project add the dependency:

dependencies:
  ...
  flutter_sodium: ^0.2.0

Import the plugin and initialize it. Sodium.init() initializes the plugin and should be called before any other function provided by flutter_sodium.

import 'package:flutter_sodium/flutter_sodium.dart';

// initialize sodium
Sodium.init();

Usage example

// Password hashing (using Argon)
final password = 'my password';
final str = PasswordHash.hashStringStorage(password);

print(str);

// verify hash str
final valid = PasswordHash.verifyStorage(str, password);

assert(valid);

This project includes an extensive example app with runnable code samples. Be sure to check it out!

API coverage

The flutter_sodium plugin implements the following libsodium APIs:

  • crypto_aead
  • crypto_auth
  • crypto_box
  • crypto_generichash
  • crypto_hash
  • crypto_kdf
  • crypto_kx
  • crypto_onetimeauth
  • crypto_pwhash
  • crypto_scalarmult
  • crypto_secretbox
  • crypto_secretstream
  • crypto_shorthash
  • crypto_sign
  • crypto_stream
  • randombytes
  • sodium_version

API coverage is not 100% complete, track the progress in issue #61

Dart APIs

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 Sodium.cryptoPwhashStr.

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.

Migrating to fluttter_sodium FFI

The FFI implementation of flutter_sodium is backwards incompatible with the previous platform channel implementation. The list of changes:

  • the entire FFI API is now synchronous, while the previous implementation was entirely asynchronous
  • all hardcoded libsodium constants are now available as properties on the Sodium class.
  • in the platform channel versions the Android and iOS implementations were not in sync. Some functions were available only in iOS, others only in Android. With the FFI implementation, there is a single API covering both platforms.

Background threads

Since the entire FFI API is synchronous, you'll need to do some extra work to execute long running crypto function on a background thread. Luckily this is very easy with Flutter's compute function.

The following code snippet demonstrates running a password hash on the background thread.

final pw = 'hello world';
final str = await compute(PasswordHash.hashStringStorageModerate, pw);

print(str);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].