Skip to content
Dart implementation of ChaCha20, a popular stream encryption algorithm.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Pub Package


A pure Dart implementation of Chacha20, a popular stream encryption algorithm. Tests utilize examples from RFC 7539, an implementation guide by the the Internet Research Task Force.

Performance on a recent Intel CPU + Dart VM is:

  • About 100MB/s when message size is 1 MB.
  • About 50MB/s when message size is 100 bytes.

Licensed under the Apache License 2.0.

A simple example

import 'dart:typed_data';

void main() {
    // ----------
    // Parameters
    // ----------
    // 256-bit (secret) key
    var key = Chacha20.randomKey();
    // 96-bit (non-secret) nonce
    var nonce = new Uint8List(12);
    // -------------
    // Convert bytes
    // -------------
    // Initialize
    final chacha20 = new Chacha20();
    chacha20.initialize(key: key, nonce: nonce);
    // convert message [1,2,3]
    // ---------------------------------------
    // Convert more messages with the same key
    // ---------------------------------------
    // It's important that we don't re-use the same (key, nonce) combination.
    // So let's increment the nonce for the next message.
    nonce = Chacha20.incrementNonceBytes(nonce);
    // ------------------
    // Converting streams
    // ------------------
    // Let's say we have the following stream
    final stream = new Stream<List<int>>.fromIterable([[1,2,3], [5], [7,11]]);
    // Initialize
    chacha20.initialize(key: key, nonce: nonce);
    // Convert chunk-by-chunk.
    // 'keyStreamIndex' is incremented when you advance in the stream.
    final convertedStream = {
      return chacha20.convert(chunk);
You can’t perform that action at this time.