crypto
crypto copied to clipboard
Support store/restore state?
I have a use-case where I'd like to store the internal state of a Hash, and then later restore it to continue the hashing of the incoming stream (upload happens in chunks with unpredictable time gap in-between). Would it be possible to support that?
The same needs
Rather than store the state of hash, store the bytes may work. Hope the following code would be useful for you.
import 'dart:math';
import 'package:crypto/crypto.dart' as Crypto;
Stream<List<int>> _generateData() async* {
var random = Random();
for (var i = 0;; ++i) {
// Simulate time-consuming operation
await Future.delayed(Duration(seconds: random.nextInt(2)));
// End this operation
if (i == 10) return;
yield Iterable.generate(random.nextInt(100), (_) => random.nextInt(255))
.toList();
}
}
void main(List<String> arguments) {
_generateData().toList().then((value) {
print(Crypto.md5.convert(
// Add all the bytes to one List
value.reduce(
(value, element) => value..addAll(element),
),
));
});
}
PS: I'm not a native speaker of English. If there are any mistakes, please correct me.