crypto chunked hash

73 views
Skip to first unread message

Istvan Soos

unread,
Sep 7, 2016, 6:18:25 AM9/7/16
to Dart Misc
Hi,

I find the crypto package a bit confusing wrt/ how to calculate sha1 hash of a big file. Does the team have an example on how they suggest doing that?

Setting the result object on the startChunkedConversion() call is not really intuitive, and as there seems to be a pending breaking change anyway, I'd suggest a different route:
  • Move sha1 and similar variables into functions that takes a List<int> and return a hash. Similar to the current convert() method, they don't store or manipulate internal state, they may not be on the class.
  • Make the Sha1Hash class implement the Sink or even the ByteConversionSink interface, and on closing, calculate the digest.
Best regards,
  Istvan

Kevin Moore

unread,
Sep 8, 2016, 1:12:12 PM9/8/16
to Dart Misc
See https://github.com/dart-lang/crypto/blob/master/example/hash.dart

This will make sure you don't load the entire file into memory. It streams into the "hasher" and you get a result when you hit the end.

Let us know if you have other issues.

Istvan Soos

unread,
Sep 8, 2016, 6:51:28 PM9/8/16
to General Dart Discussion
Thanks Kevin,

That is neat, it would be worth to put the bind part of that example
into the readme.

Thanks,
Istvan
> --
> For other discussions, see https://groups.google.com/a/dartlang.org/
>
> For HOWTO questions, visit http://stackoverflow.com/tags/dart
>
> To file a bug report or feature request, go to http://www.dartbug.com/new
> ---
> You received this message because you are subscribed to the Google Groups
> "Dart Misc" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to misc+uns...@dartlang.org.

Kevin Moore

unread,
Sep 15, 2016, 3:46:16 PM9/15/16
to Dart Misc
File an issue on the crypto repo – a great suggestion!

You received this message because you are subscribed to a topic in the Google Groups "Dart Misc" group.
To unsubscribe from this topic, visit https://groups.google.com/a/dartlang.org/d/topic/misc/PK0A5YaeO7E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to misc+uns...@dartlang.org.


Reply all
Reply to author
Forward
0 new messages