[amscotti@128bit.io ~/posts]# cat md5-hashing-in-dart.md _
# MD5 hashing in Dart
- May 04, 2013 | 1 min read

Here is some Dart code for doing MD5, though at this point in time, MD5 is becoming obsolete in favor of SHA1. But as I have done code for MD5 in other languages I figured I would duplicate the code for another comparison. To look at the languages, checkout MD5 hashing in Python, Ruby and Groovy and MD5 hashing in CoffeeScript, Perl and Scala.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import 'dart:crypto';

void main() {

  //Quick MD5 of text
  var text = "MD5 this text!";
  var md5hash1 = CryptoUtils.bytesToHex((new MD5()..add(text.codeUnits)).close());

  //MD5 of text with updates
  var m = new MD5();
  m.add("MD5 ".codeUnits);
  m.add("this ".codeUnits);
  m.add("text!".codeUnits);
  var md5hash2 = CryptoUtils.bytesToHex(m.close());

  //Output
  print("${md5hash1} should be the same as ${md5hash2}");
}

I do like how you can use Method Cascades, this is something that I really wish Java had in it because the code is much cleaner in my opinion.

I am hoping to have some time to play around with Dart's Isolates. It is like a cross between JavaScript's Web Worker and Erlang or Scala actors.

Got a way to make the code better? Fork the Gist or comment on Github.