cryptography_flutter 2.1.1 cryptography_flutter: ^2.1.1 copied to clipboard
Makes 'package:cryptography' use platform APIs in Android, iOS, and Mac OS X. The package can make performance up to 100 times better.
Overview #
This is a version of the package cryptography that optimizes performance of some cryptographic algorithms by using native APIs of Android, iOS, and Mac OS X. You must use asynchronous methods to get the performance boost.
Maintained by Gohilla. Licensed under the Apache License 2.0.
General behavior #
This package contains two kinds of classes:
- Classes such as FlutterChacha20
use operating system APIs in Android / iOS / Mac OS X. If the operating system does not support
the algorithm, the background implementation (such as
BackgroundChacha20
) or a pure Dart implementation (such as DartChacha20) when available. - Classes such as BackgroundChacha20 move the computation away from the UI isolate using compute ("package:flutter/foundation.dart").
Both compute very small inputs in the same isolate if the overhead of message passing does not make sense. For example, if you encrypt a 16 byte message, the computation is done in the same isolate. Too large inputs are also computed in the same isolate (because you probably should not allocate a gigabyte cross-isolate message on a mobile phone). We also have a queue to prevent memory exhaustion that could happen if you send lots of requests concurrently (something we observed during testing).
Getting started #
In pubspec.yaml:
dependencies:
cryptography: ^2.1.0
cryptography_flutter: ^2.1.0
Then just use:
import 'package:cryptography_flutter/cryptography_flutter.dart';
void main() {
// Enable use of operating system APIs.
// This is an optional performance optimization.
FlutterCryptography.enable();
// ....
}
For APIs, read documentation for package:cryptography.
Optimizations by platform #
In iOS and Mac OS X #
Calling FlutterCryptography.enable()
enables:
- FlutterAesGcm
- Our benchmarks have shown up to ~50 times better performance.
- FlutterChacha20
- Our benchmarks have shown up to ~10 times better performance.
- FlutterEd25519
- Our benchmarks have shown up to ~10 times better performance.
- FlutterX25519
- Our benchmarks have shown up to ~10 times better performance.
By default, maximum input size is 100 MB.
In Android #
We have observe problems with some Android devices. Therefore we have disabled some optimizations until we have time to investigate the problems.
Calling FlutterCryptography.enable()
enables:
- FlutterAesGcm
- Our benchmarks have shown up to ~50 times better performance.
- FlutterChacha20
- Our benchmarks have shown up to ~10 times better performance.
- BackgroundEd25519
- BackgroundX25519
By default, maximum input size is 20 MB because of memory allocation crashes we observed during testing.
In other platforms #
In browsers, nothing is changed.
In Windows, Linux, and other platforms:
Links #
Contributing? #
This is how you run the tests:
./tool/test.sh
Alternatively:
flutter test --no-pub
cd example
flutter test --no-pub integration_test