Skip to content
pubscout

sodium

4.1.2+1, released 3 weeks ago by skycoder42.de

Dart bindings for the libsodium cryptographic library for Dart-VM and Web.

WASM-ready
$ flutter pub add sodium
Source repository

What it does

Provides an easy-to-use Dart API that mirrors the native libsodium C API, supporting secret-key cryptography, public-key signatures, hashing, random data generation, and more. Works on Android, iOS, Linux, Windows, macOS, and Web.

AI-written summary of version 4.1.2+1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need robust, high-performance cryptographic operations (encryption, hashing, digital signatures) in your Dart or Flutter app.
  • You need cross-platform cryptographic support for both native platforms and the web.

Skip it when

  • You only need simple base64 or basic hashing functions that are already covered by standard Dart libraries like `dart:convert` or `crypto` without native binary dependencies.
  • You want a purely pure-Dart implementation of cryptographic primitives without relying on native compilation or WASM/JS bundling.

Strengths

  • Supports all major platforms including Dart-VM and Web.
  • Leverages native build hooks to build native dependencies on demand.
  • Provides SecureKey wrappers for managing sensitive material in memory securely.

Weaknesses

  • Requires proper cleanup (disposing of `SecureKey` instances) to avoid memory leaks.
  • Web deployment requires manually downloading and adding the `sodium.js` script to your project via helper commands.

Setup

Kind
FFI (native library)
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
12

Add the dependency to pubspec.yaml. For web targets, you must run `dart run sodium:update_web` to download and integrate `sodium.js`. Native platforms build dependencies automatically using build hooks.

import 'package:sodium/sodium.dart';

final sodium = await SodiumInit.init();
final nonce = sodium.randombytes.buf(sodium.crypto.secretBox.nonceBytes);
final key = sodium.crypto.secretBox.keygen();
key.dispose();

Alternatives

Packages that do the same job and could replace sodium.

  • web

    Lightweight bindings for browser APIs via JS interop

  • fhir_path

    Model-independent FHIRPath evaluation engine in Dart, port of the Java reference implementation.

  • oqs

    Dart FFI bindings for liboqs enabling post-quantum cryptography primitives like ML-KEM and ML-DSA.

  • node_interop

    Dart bindings for Node.js core modules

Works with

Packages commonly used together with sodium: ones it builds on, ones built on it, and its own family.