cryptography 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new75

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.

0.1.2 #

  • Improved documentation

0.1.1 #

  • Fixed example

0.1.0 #

  • Initial version

example/example.dart

import 'package:cryptography/cryptography.dart';

void chacha20_example() {
  // 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);
}

void x25519_example() async {
  // Let's generate two asymmetric keypair.
  final keypair1 = x25519.newKeyPair();
  final keypair2 = x25519.newKeyPair();

  // We can now calculate a shared secret
  var sharedSecret = x25519.sharedSecret(
    keypair1.secretKey,
    keypair2.publicKey,
  );
  print(sharedSecret.toHex());
}

Use this package as a library

1. Depend on it

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


dependencies:
  cryptography: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:cryptography/cryptography.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
50
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:cryptography/cryptography.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
collection ^1.14.0 1.14.12
crypto ^2.1.3 2.1.3
meta ^1.1.0 1.1.7
Transitive dependencies
charcode 1.1.2
convert 2.1.1
typed_data 1.1.6
Dev dependencies
benchmark_harness ^1.0.0
pedantic ^1.8.0
raw any
test ^1.6.0