toSync method

  1. @override
DartChacha20 toSync()
override

Returns a synchronous, pure Dart implementation of this cipher.

Pure Dart implementations can be slower than implementations that use platform APIs. Therefore you shouldn't use this method unless you really need to.

Example

import 'package:cryptography/cryptography.dart';

void main() {
  final cipher = Chacha20.poly1305Aead().toSync();
  final secretKey = cipher.newSecretKeySync();
  final secretBox = cipher.encryptSync(
    [1,2,3],
    secretKey,
  );
}

Implementation

@override
DartChacha20 toSync() {
  if (macAlgorithm is DartChacha20Poly1305AeadMacAlgorithm) {
    return DartChacha20.poly1305Aead(
      random: random,
    );
  }
  return DartChacha20(
    macAlgorithm: macAlgorithm,
    random: random,
  );
}