nankee / yamd5.js

Yet another javascript MD5 hasher: Fastest out there (for not-small strings). Support for Unicode strings. Natively incremental.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YaMD5 - Yet another MD5 hasher

I needed an MD5 hasher, and as usual I want small code base, and fast.

Originally found md5-o-matic. It was fast but did not work with Unicode strings. Also, I eventually realized it was really based on code from Joseph Myers, which is itself a javascript adapation of the C language version the reference implementation of MD5 in Appendix 3 of RFC 1321.

Then I found SparkMD5, which works with Unicode strings, but at a steep cost to performance on large input strings. Also, glancing at the code I saw avoidable redundancies causing the code base to be larger than needed.

So from this point I set out to write my own version, YaMD5 (sorry, I am not good with naming projects), of course heavily relying on the original code from Joseph Myers, (with modifications to incrementally improve performance as per profiling), and bits from SparkMD5 -- I started to work from SparkMD5 implementation, so there might be code original to SparkMD5 I kept in a few places (like say, code in md5.end() etc.)

Benefits of YaMD5

Usage

One pass:

YaMD5.hashStr('hello world\n') === "6f5902ac237024bdd0c176cb93063dc4"

Incremental:

var md5Hasher = new YaMD5();
...
md5Hasher.start();
md5Hasher.appendStr('hello');
md5Hasher.appendStr(' ');
md5Hasher.appendStr('world');
md5Hasher.appendStr('\n');
md5Hasher.end() === '6f5902ac237024bdd0c176cb93063dc4';

License

I don't know what license covers Joseph Myers' code (need to find out). In any case, concerning whatever original code I contributed in there:

The MIT License (MIT)

Copyright (C) 2014 Raymond Hill

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Yet another javascript MD5 hasher: Fastest out there (for not-small strings). Support for Unicode strings. Natively incremental.


Languages

Language:JavaScript 91.0%Language:HTML 9.0%