HTML Data Port

© 2005 Goetz Heller

Table of Contents Description Source Code Copyright Note back

The MD5 Hash Algorithm - Examples

      document.write('<'+'h4><'+'em>Run Tests From <'+'a href="http://www.faqs.org/rfcs/rfc1321.html" target="RFC"'+'>RFC1321<'+'/a>:'+'<'+'/em><'+'/h4>');
      var md5 = core.createInstance('system.security.encryption.hash.MD5');
      var inp = [
        "",
        "a",
        "abc",
        "message digest",
        "abcdefghijklmnopqrstuvwxyz",
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
        "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
      ];
      for (var j = 0; j < inp.length; j++) {
        var d = md5.computeHash(inp[j]);
        var s = '';
        for (var i = 0; i < d.length; i++) {
          s += ((d.charCodeAt(i) < 16) ? '0' : '') + d.charCodeAt(i).toString(16);
        }
        document.write('md5.computeHash(\''+inp[j]+'\') = \'' + s +'\'<'+'br/>');
      }