Pub Package Build Status

Introduction

A collection of cryptographic algorithms implemented in Dart.

The package is licensed under the Apache License 2.0. Two previously separate packages, chacha20 and curve25519, have been merged into this package.

Contributing

Algorithms

Elliptic curve cryptography

  • X25519 (Curve25519)
  • (Additional algorithms are welcomed)

Ciphers

  • Chacha20
  • (Additional algorithms are welcomed)

Hashes

  • SHA2 (224/256/384/512)
  • (Additional algorithms are welcomed)

Other

  • HMAC

Details

Chacha20

Tests use examples from RFC 7539, an implementation guide by the the Internet Research Task Force.

Performance on new Apple laptops is about 50-100MB/s. Optimized C implementations can be up to a magnitude faster.

An example:

import 'package:cryptography/cryptography.dart';

void main() {
  // Generate a random 256-bit secret key
  final secretKey = chacha20.newSecretKey();

  // Generate a random 96-bit nonce.
  final nonce = chacha20.newNonce();

  // Encrypt
  final result = chacha20.encrypt(
    [1, 2, 3],
    secretKey,
    nonce: nonce,
  );
  print(result);
}

X25519

X25519 is Elliptic Curve Diffie-Hellman (ECDH) over Curve25519. Tests use test vectors from X25519 key exchange specification (RFC 7748) and an additional 10,000 round test vector.

Performance on new Apple laptops is about 1k operations per second. Optimized C implementations can be up to a magnitude faster.

Libraries

cryptography
A collection of cryptographic algorithms.
cryptography.math
Functions for implementing cryptographic algorithms.