newHashSink method

  1. @override
DartHashSink newHashSink()
inherited

Constructs a sink for hashing chunks.

Example

An example with Sha256:

import 'package:cryptography_plus/cryptography_plus.dart';

void main() async {
  // Create a sink
  final algorithm = Sha256();
  final sink = algorithm.newHashSink();

  // Add all parts
  sink.add(<int>[1,2,3]);
  sink.add(<int>[4,5]);

  // Calculate hash
  sink.close();
  final hash = await sink.hash();

  print('Hash: ${hash.bytes}');
}

Implementation

@override
DartHashSink newHashSink() {
  final captureSink = PackageCryptoDigestCaptureSink();
  final implSink = impl.startChunkedConversion(captureSink);
  return PackageCryptoHashSink(
    Uint8List(hashLengthInBytes),
    impl,
    implSink,
    captureSink,
  );
}