Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "js-md5", | ||
"version": "0.3.0", | ||
"main": ["build/md5.min.js"], | ||
"version": "0.4.0", | ||
"main": ["src/md5.js"], | ||
"ignore": [ | ||
@@ -6,0 +6,0 @@ "samples", |
@@ -1,22 +0,10 @@ | ||
/* | ||
* js-md5 v0.3.0 | ||
* https://github.com/emn178/js-md5 | ||
/** | ||
* [js-md5]{@link https://github.com/emn178/js-md5} | ||
* | ||
* Copyright 2014-2015, emn178@gmail.com | ||
* | ||
* Licensed under the MIT license: | ||
* http://www.opensource.org/licenses/MIT | ||
* @namespace md5 | ||
* @version 0.4.0 | ||
* @author Yi-Cyuan Chen [emn178@gmail.com] | ||
* @copyright Yi-Cyuan Chen 2014-2015 | ||
* @license MIT | ||
*/ | ||
(function(q,F){var u="undefined"!=typeof module;u&&(q=global,q.JS_MD5_TEST&&(q.navigator={userAgent:"Firefox"}));var C=(q.JS_MD5_TEST||!u)&&-1!=navigator.userAgent.indexOf("Firefox"),y=!q.JS_MD5_TEST&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),D=[128,32768,8388608,-2147483648],t=[0,8,16,24],e=[],r;if(y){var A=new ArrayBuffer(68);r=new Uint8Array(A);e=new Uint32Array(A)}var x=function(g){var q="string"!=typeof g;q&&g.constructor==ArrayBuffer&&(g=new Uint8Array(g));var k,l,m,n,b, | ||
a,d,c,h,u=!0,x=!1,p=0,v=0,z=0,w=g.length;e[16]=0;do{e[0]=e[16];e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0;if(q)if(y)for(a=v;p<w&&64>a;++p)r[a++]=g[p];else for(a=v;p<w&&64>a;++p)e[a>>2]|=g[p]<<t[a++&3];else if(y)for(a=v;p<w&&64>a;++p)b=g.charCodeAt(p),128>b?r[a++]=b:(2048>b?r[a++]=192|b>>6:(55296>b||57344<=b?r[a++]=224|b>>12:(b=65536+((b&1023)<<10|g.charCodeAt(++p)&1023),r[a++]=240|b>>18,r[a++]=128|b>>12&63),r[a++]=128|b>>6&63),r[a++]=128|b&63);else for(a= | ||
v;p<w&&64>a;++p)b=g.charCodeAt(p),128>b?e[a>>2]|=b<<t[a++&3]:(2048>b?e[a>>2]|=(192|b>>6)<<t[a++&3]:(55296>b||57344<=b?e[a>>2]|=(224|b>>12)<<t[a++&3]:(b=65536+((b&1023)<<10|g.charCodeAt(++p)&1023),e[a>>2]|=(240|b>>18)<<t[a++&3],e[a>>2]|=(128|b>>12&63)<<t[a++&3]),e[a>>2]|=(128|b>>6&63)<<t[a++&3]),e[a>>2]|=(128|b&63)<<t[a++&3]);z+=a-v;v=a-64;p==w&&(e[a>>2]|=D[a&3],++p);p>w&&56>a&&(e[14]=z<<3,x=!0);u?(b=e[0]-680876937,b=(b<<7|b>>>25)-271733879<<0,c=(-1732584194^b&2004318071)+e[1]-117830708,c=(c<<12|c>>> | ||
20)+b<<0,d=(-271733879^c&(b^-271733879))+e[2]-1126478375,d=(d<<17|d>>>15)+c<<0,a=(b^d&(c^b))+e[3]-1316259209):(b=k,a=l,d=m,c=n,b+=(c^a&(d^c))+e[0]-680876936,b=(b<<7|b>>>25)+a<<0,c+=(d^b&(a^d))+e[1]-389564586,c=(c<<12|c>>>20)+b<<0,d+=(a^c&(b^a))+e[2]+606105819,d=(d<<17|d>>>15)+c<<0,a+=(b^d&(c^b))+e[3]-1044525330);a=(a<<22|a>>>10)+d<<0;b+=(c^a&(d^c))+e[4]-176418897;b=(b<<7|b>>>25)+a<<0;c+=(d^b&(a^d))+e[5]+1200080426;c=(c<<12|c>>>20)+b<<0;d+=(a^c&(b^a))+e[6]-1473231341;d=(d<<17|d>>>15)+c<<0;a+=(b^d& | ||
(c^b))+e[7]-45705983;a=(a<<22|a>>>10)+d<<0;b+=(c^a&(d^c))+e[8]+1770035416;b=(b<<7|b>>>25)+a<<0;c+=(d^b&(a^d))+e[9]-1958414417;c=(c<<12|c>>>20)+b<<0;d+=(a^c&(b^a))+e[10]-42063;d=(d<<17|d>>>15)+c<<0;a+=(b^d&(c^b))+e[11]-1990404162;a=(a<<22|a>>>10)+d<<0;b+=(c^a&(d^c))+e[12]+1804603682;b=(b<<7|b>>>25)+a<<0;c+=(d^b&(a^d))+e[13]-40341101;c=(c<<12|c>>>20)+b<<0;d+=(a^c&(b^a))+e[14]-1502002290;d=(d<<17|d>>>15)+c<<0;a+=(b^d&(c^b))+e[15]+1236535329;a=(a<<22|a>>>10)+d<<0;b+=(d^c&(a^d))+e[1]-165796510;b=(b<<5| | ||
b>>>27)+a<<0;c+=(a^d&(b^a))+e[6]-1069501632;c=(c<<9|c>>>23)+b<<0;d+=(b^a&(c^b))+e[11]+643717713;d=(d<<14|d>>>18)+c<<0;a+=(c^b&(d^c))+e[0]-373897302;a=(a<<20|a>>>12)+d<<0;b+=(d^c&(a^d))+e[5]-701558691;b=(b<<5|b>>>27)+a<<0;c+=(a^d&(b^a))+e[10]+38016083;c=(c<<9|c>>>23)+b<<0;d+=(b^a&(c^b))+e[15]-660478335;d=(d<<14|d>>>18)+c<<0;a+=(c^b&(d^c))+e[4]-405537848;a=(a<<20|a>>>12)+d<<0;b+=(d^c&(a^d))+e[9]+568446438;b=(b<<5|b>>>27)+a<<0;c+=(a^d&(b^a))+e[14]-1019803690;c=(c<<9|c>>>23)+b<<0;d+=(b^a&(c^b))+e[3]- | ||
187363961;d=(d<<14|d>>>18)+c<<0;a+=(c^b&(d^c))+e[8]+1163531501;a=(a<<20|a>>>12)+d<<0;b+=(d^c&(a^d))+e[13]-1444681467;b=(b<<5|b>>>27)+a<<0;c+=(a^d&(b^a))+e[2]-51403784;c=(c<<9|c>>>23)+b<<0;d+=(b^a&(c^b))+e[7]+1735328473;d=(d<<14|d>>>18)+c<<0;a+=(c^b&(d^c))+e[12]-1926607734;a=(a<<20|a>>>12)+d<<0;h=a^d;b+=(h^c)+e[5]-378558;b=(b<<4|b>>>28)+a<<0;c+=(h^b)+e[8]-2022574463;c=(c<<11|c>>>21)+b<<0;h=c^b;d+=(h^a)+e[11]+1839030562;d=(d<<16|d>>>16)+c<<0;a+=(h^d)+e[14]-35309556;a=(a<<23|a>>>9)+d<<0;h=a^d;b+=(h^ | ||
c)+e[1]-1530992060;b=(b<<4|b>>>28)+a<<0;c+=(h^b)+e[4]+1272893353;c=(c<<11|c>>>21)+b<<0;h=c^b;d+=(h^a)+e[7]-155497632;d=(d<<16|d>>>16)+c<<0;a+=(h^d)+e[10]-1094730640;a=(a<<23|a>>>9)+d<<0;h=a^d;b+=(h^c)+e[13]+681279174;b=(b<<4|b>>>28)+a<<0;c+=(h^b)+e[0]-358537222;c=(c<<11|c>>>21)+b<<0;h=c^b;d+=(h^a)+e[3]-722521979;d=(d<<16|d>>>16)+c<<0;a+=(h^d)+e[6]+76029189;a=(a<<23|a>>>9)+d<<0;h=a^d;b+=(h^c)+e[9]-640364487;b=(b<<4|b>>>28)+a<<0;c+=(h^b)+e[12]-421815835;c=(c<<11|c>>>21)+b<<0;h=c^b;d+=(h^a)+e[15]+530742520; | ||
d=(d<<16|d>>>16)+c<<0;a+=(h^d)+e[2]-995338651;a=(a<<23|a>>>9)+d<<0;b+=(d^(a|~c))+e[0]-198630844;b=(b<<6|b>>>26)+a<<0;c+=(a^(b|~d))+e[7]+1126891415;c=(c<<10|c>>>22)+b<<0;d+=(b^(c|~a))+e[14]-1416354905;d=(d<<15|d>>>17)+c<<0;a+=(c^(d|~b))+e[5]-57434055;a=(a<<21|a>>>11)+d<<0;b+=(d^(a|~c))+e[12]+1700485571;b=(b<<6|b>>>26)+a<<0;c+=(a^(b|~d))+e[3]-1894986606;c=(c<<10|c>>>22)+b<<0;d+=(b^(c|~a))+e[10]-1051523;d=(d<<15|d>>>17)+c<<0;a+=(c^(d|~b))+e[1]-2054922799;a=(a<<21|a>>>11)+d<<0;b+=(d^(a|~c))+e[8]+1873313359; | ||
b=(b<<6|b>>>26)+a<<0;c+=(a^(b|~d))+e[15]-30611744;c=(c<<10|c>>>22)+b<<0;d+=(b^(c|~a))+e[6]-1560198380;d=(d<<15|d>>>17)+c<<0;a+=(c^(d|~b))+e[13]+1309151649;a=(a<<21|a>>>11)+d<<0;b+=(d^(a|~c))+e[4]-145523070;b=(b<<6|b>>>26)+a<<0;c+=(a^(b|~d))+e[11]-1120210379;c=(c<<10|c>>>22)+b<<0;d+=(b^(c|~a))+e[2]+718787259;d=(d<<15|d>>>17)+c<<0;a+=(c^(d|~b))+e[9]-343485551;a=(a<<21|a>>>11)+d<<0;u?(k=b+1732584193<<0,l=a-271733879<<0,m=d-1732584194<<0,n=c+271733878<<0,u=!1):(k=k+b<<0,l=l+a<<0,m=m+d<<0,n=n+c<<0)}while(!x); | ||
return C?(g=f[k>>4&15]+f[k&15],g+=f[k>>12&15]+f[k>>8&15],g+=f[k>>20&15]+f[k>>16&15],g+=f[k>>28&15]+f[k>>24&15],g+=f[l>>4&15]+f[l&15],g+=f[l>>12&15]+f[l>>8&15],g+=f[l>>20&15]+f[l>>16&15],g+=f[l>>28&15]+f[l>>24&15],g+=f[m>>4&15]+f[m&15],g+=f[m>>12&15]+f[m>>8&15],g+=f[m>>20&15]+f[m>>16&15],g+=f[m>>28&15]+f[m>>24&15],g+=f[n>>4&15]+f[n&15],g+=f[n>>12&15]+f[n>>8&15],g+=f[n>>20&15]+f[n>>16&15],g+=f[n>>28&15]+f[n>>24&15]):f[k>>4&15]+f[k&15]+f[k>>12&15]+f[k>>8&15]+f[k>>20&15]+f[k>>16&15]+f[k>>28&15]+f[k>> | ||
24&15]+f[l>>4&15]+f[l&15]+f[l>>12&15]+f[l>>8&15]+f[l>>20&15]+f[l>>16&15]+f[l>>28&15]+f[l>>24&15]+f[m>>4&15]+f[m&15]+f[m>>12&15]+f[m>>8&15]+f[m>>20&15]+f[m>>16&15]+f[m>>28&15]+f[m>>24&15]+f[n>>4&15]+f[n&15]+f[n>>12&15]+f[n>>8&15]+f[n>>20&15]+f[n>>16&15]+f[n>>28&15]+f[n>>24&15]};if(!q.JS_MD5_TEST&&u){var B=require("crypto"),E=require("buffer").Buffer;module.exports=function(e){if("string"==typeof e)return 80>=e.length||183>=e.length&&!/[^\x00-\x7F]/.test(e)?x(e):B.createHash("md5").update(e,"utf8").digest("hex"); | ||
e.constructor==ArrayBuffer&&(e=new Uint8Array(e));return 370>=e.length?x(e):B.createHash("md5").update(new E(e)).digest("hex")}}else q&&(q.md5=x)})(this); | ||
!function(t){"use strict";function e(t){if(t)c[0]=c[16]=c[1]=c[2]=c[3]=c[4]=c[5]=c[6]=c[7]=c[8]=c[9]=c[10]=c[11]=c[12]=c[13]=c[14]=c[15]=0,this.blocks=c,this.buffer8=r;else if(n){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=0,this.finalized=this.hashed=!1,this.first=!0}var h="object"==typeof process&&process.versions&&process.versions.node;h&&(t=global);var r,i=!t.JS_MD5_TEST&&"object"==typeof module&&module.exports,s="function"==typeof define&&define.amd,n=!t.JS_MD5_TEST&&"undefined"!=typeof ArrayBuffer,o="0123456789abcdef".split(""),f=[128,32768,8388608,-2147483648],a=[0,8,16,24],u=["hex","array","digest","buffer"],c=[];if(n){var d=new ArrayBuffer(68);r=new Uint8Array(d),c=new Uint32Array(d)}var l=function(t){return function(h){return new e(!0).update(h)[t]()}},y=function(){var t=l("hex");h&&(t=p(t)),t.create=function(){return new e},t.update=function(e){return t.create().update(e)};for(var r=0;r<u.length;++r){var i=u[r];t[i]=l(i)}return t},p=function(e){var h,r;try{if(t.JS_MD5_TEST)throw"JS_MD5_TEST";h=require("crypto"),r=require("buffer").Buffer}catch(i){return console.log(i),e}var s=function(t){if("string"==typeof t)return t.length<=s.utf8Threshold?e(t):t.length<=s.asciiThreshold&&!/[^\x00-\x7F]/.test(t)?e(t):h.createHash("md5").update(t,"utf8").digest("hex");if(t.constructor==ArrayBuffer)t=new Uint8Array(t);else if(void 0===t.length||t.length<=s.bytesThreshold)return e(t);return h.createHash("md5").update(new r(t)).digest("hex")};return s.utf8Threshold=18,s.asciiThreshold=60,s.bytesThreshold=245,s};e.prototype.update=function(e){if(!this.finalized){var h="string"!=typeof e;h&&e.constructor==t.ArrayBuffer&&(e=new Uint8Array(e));for(var r,i,s=0,o=e.length||0,f=this.blocks,u=this.buffer8;o>s;){if(this.hashed&&(this.hashed=!1,f[0]=f[16],f[16]=f[1]=f[2]=f[3]=f[4]=f[5]=f[6]=f[7]=f[8]=f[9]=f[10]=f[11]=f[12]=f[13]=f[14]=f[15]=0),h)if(n)for(i=this.start;o>s&&64>i;++s)u[i++]=e[s];else for(i=this.start;o>s&&64>i;++s)f[i>>2]|=e[s]<<a[3&i++];else if(n)for(i=this.start;o>s&&64>i;++s)r=e.charCodeAt(s),128>r?u[i++]=r:2048>r?(u[i++]=192|r>>6,u[i++]=128|63&r):55296>r||r>=57344?(u[i++]=224|r>>12,u[i++]=128|r>>6&63,u[i++]=128|63&r):(r=65536+((1023&r)<<10|1023&e.charCodeAt(++s)),u[i++]=240|r>>18,u[i++]=128|r>>12&63,u[i++]=128|r>>6&63,u[i++]=128|63&r);else for(i=this.start;o>s&&64>i;++s)r=e.charCodeAt(s),128>r?f[i>>2]|=r<<a[3&i++]:2048>r?(f[i>>2]|=(192|r>>6)<<a[3&i++],f[i>>2]|=(128|63&r)<<a[3&i++]):55296>r||r>=57344?(f[i>>2]|=(224|r>>12)<<a[3&i++],f[i>>2]|=(128|r>>6&63)<<a[3&i++],f[i>>2]|=(128|63&r)<<a[3&i++]):(r=65536+((1023&r)<<10|1023&e.charCodeAt(++s)),f[i>>2]|=(240|r>>18)<<a[3&i++],f[i>>2]|=(128|r>>12&63)<<a[3&i++],f[i>>2]|=(128|r>>6&63)<<a[3&i++],f[i>>2]|=(128|63&r)<<a[3&i++]);this.lastByteIndex=i,this.bytes+=i-this.start,i>=64?(this.start=i-64,this.hash(),this.hashed=!0):this.start=i}return this}},e.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex;t[e>>2]|=f[3&e],e>=56&&(this.hashed||this.hash(),t[0]=t[16],t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.bytes<<3,this.hash()}},e.prototype.hash=function(){var t,e,h,r,i,s,n=this.blocks;this.first?(t=n[0]-680876937,t=(t<<7|t>>>25)-271733879<<0,r=(-1732584194^2004318071&t)+n[1]-117830708,r=(r<<12|r>>>20)+t<<0,h=(-271733879^r&(-271733879^t))+n[2]-1126478375,h=(h<<17|h>>>15)+r<<0,e=(t^h&(r^t))+n[3]-1316259209,e=(e<<22|e>>>10)+h<<0):(t=this.h0,e=this.h1,h=this.h2,r=this.h3,t+=(r^e&(h^r))+n[0]-680876936,t=(t<<7|t>>>25)+e<<0,r+=(h^t&(e^h))+n[1]-389564586,r=(r<<12|r>>>20)+t<<0,h+=(e^r&(t^e))+n[2]+606105819,h=(h<<17|h>>>15)+r<<0,e+=(t^h&(r^t))+n[3]-1044525330,e=(e<<22|e>>>10)+h<<0),t+=(r^e&(h^r))+n[4]-176418897,t=(t<<7|t>>>25)+e<<0,r+=(h^t&(e^h))+n[5]+1200080426,r=(r<<12|r>>>20)+t<<0,h+=(e^r&(t^e))+n[6]-1473231341,h=(h<<17|h>>>15)+r<<0,e+=(t^h&(r^t))+n[7]-45705983,e=(e<<22|e>>>10)+h<<0,t+=(r^e&(h^r))+n[8]+1770035416,t=(t<<7|t>>>25)+e<<0,r+=(h^t&(e^h))+n[9]-1958414417,r=(r<<12|r>>>20)+t<<0,h+=(e^r&(t^e))+n[10]-42063,h=(h<<17|h>>>15)+r<<0,e+=(t^h&(r^t))+n[11]-1990404162,e=(e<<22|e>>>10)+h<<0,t+=(r^e&(h^r))+n[12]+1804603682,t=(t<<7|t>>>25)+e<<0,r+=(h^t&(e^h))+n[13]-40341101,r=(r<<12|r>>>20)+t<<0,h+=(e^r&(t^e))+n[14]-1502002290,h=(h<<17|h>>>15)+r<<0,e+=(t^h&(r^t))+n[15]+1236535329,e=(e<<22|e>>>10)+h<<0,t+=(h^r&(e^h))+n[1]-165796510,t=(t<<5|t>>>27)+e<<0,r+=(e^h&(t^e))+n[6]-1069501632,r=(r<<9|r>>>23)+t<<0,h+=(t^e&(r^t))+n[11]+643717713,h=(h<<14|h>>>18)+r<<0,e+=(r^t&(h^r))+n[0]-373897302,e=(e<<20|e>>>12)+h<<0,t+=(h^r&(e^h))+n[5]-701558691,t=(t<<5|t>>>27)+e<<0,r+=(e^h&(t^e))+n[10]+38016083,r=(r<<9|r>>>23)+t<<0,h+=(t^e&(r^t))+n[15]-660478335,h=(h<<14|h>>>18)+r<<0,e+=(r^t&(h^r))+n[4]-405537848,e=(e<<20|e>>>12)+h<<0,t+=(h^r&(e^h))+n[9]+568446438,t=(t<<5|t>>>27)+e<<0,r+=(e^h&(t^e))+n[14]-1019803690,r=(r<<9|r>>>23)+t<<0,h+=(t^e&(r^t))+n[3]-187363961,h=(h<<14|h>>>18)+r<<0,e+=(r^t&(h^r))+n[8]+1163531501,e=(e<<20|e>>>12)+h<<0,t+=(h^r&(e^h))+n[13]-1444681467,t=(t<<5|t>>>27)+e<<0,r+=(e^h&(t^e))+n[2]-51403784,r=(r<<9|r>>>23)+t<<0,h+=(t^e&(r^t))+n[7]+1735328473,h=(h<<14|h>>>18)+r<<0,e+=(r^t&(h^r))+n[12]-1926607734,e=(e<<20|e>>>12)+h<<0,i=e^h,t+=(i^r)+n[5]-378558,t=(t<<4|t>>>28)+e<<0,r+=(i^t)+n[8]-2022574463,r=(r<<11|r>>>21)+t<<0,s=r^t,h+=(s^e)+n[11]+1839030562,h=(h<<16|h>>>16)+r<<0,e+=(s^h)+n[14]-35309556,e=(e<<23|e>>>9)+h<<0,i=e^h,t+=(i^r)+n[1]-1530992060,t=(t<<4|t>>>28)+e<<0,r+=(i^t)+n[4]+1272893353,r=(r<<11|r>>>21)+t<<0,s=r^t,h+=(s^e)+n[7]-155497632,h=(h<<16|h>>>16)+r<<0,e+=(s^h)+n[10]-1094730640,e=(e<<23|e>>>9)+h<<0,i=e^h,t+=(i^r)+n[13]+681279174,t=(t<<4|t>>>28)+e<<0,r+=(i^t)+n[0]-358537222,r=(r<<11|r>>>21)+t<<0,s=r^t,h+=(s^e)+n[3]-722521979,h=(h<<16|h>>>16)+r<<0,e+=(s^h)+n[6]+76029189,e=(e<<23|e>>>9)+h<<0,i=e^h,t+=(i^r)+n[9]-640364487,t=(t<<4|t>>>28)+e<<0,r+=(i^t)+n[12]-421815835,r=(r<<11|r>>>21)+t<<0,s=r^t,h+=(s^e)+n[15]+530742520,h=(h<<16|h>>>16)+r<<0,e+=(s^h)+n[2]-995338651,e=(e<<23|e>>>9)+h<<0,t+=(h^(e|~r))+n[0]-198630844,t=(t<<6|t>>>26)+e<<0,r+=(e^(t|~h))+n[7]+1126891415,r=(r<<10|r>>>22)+t<<0,h+=(t^(r|~e))+n[14]-1416354905,h=(h<<15|h>>>17)+r<<0,e+=(r^(h|~t))+n[5]-57434055,e=(e<<21|e>>>11)+h<<0,t+=(h^(e|~r))+n[12]+1700485571,t=(t<<6|t>>>26)+e<<0,r+=(e^(t|~h))+n[3]-1894986606,r=(r<<10|r>>>22)+t<<0,h+=(t^(r|~e))+n[10]-1051523,h=(h<<15|h>>>17)+r<<0,e+=(r^(h|~t))+n[1]-2054922799,e=(e<<21|e>>>11)+h<<0,t+=(h^(e|~r))+n[8]+1873313359,t=(t<<6|t>>>26)+e<<0,r+=(e^(t|~h))+n[15]-30611744,r=(r<<10|r>>>22)+t<<0,h+=(t^(r|~e))+n[6]-1560198380,h=(h<<15|h>>>17)+r<<0,e+=(r^(h|~t))+n[13]+1309151649,e=(e<<21|e>>>11)+h<<0,t+=(h^(e|~r))+n[4]-145523070,t=(t<<6|t>>>26)+e<<0,r+=(e^(t|~h))+n[11]-1120210379,r=(r<<10|r>>>22)+t<<0,h+=(t^(r|~e))+n[2]+718787259,h=(h<<15|h>>>17)+r<<0,e+=(r^(h|~t))+n[9]-343485551,e=(e<<21|e>>>11)+h<<0,this.first?(this.h0=t+1732584193<<0,this.h1=e-271733879<<0,this.h2=h-1732584194<<0,this.h3=r+271733878<<0,this.first=!1):(this.h0=this.h0+t<<0,this.h1=this.h1+e<<0,this.h2=this.h2+h<<0,this.h3=this.h3+r<<0)},e.prototype.hex=function(){this.finalize();var t=this.h0,e=this.h1,h=this.h2,r=this.h3;return o[t>>4&15]+o[15&t]+o[t>>12&15]+o[t>>8&15]+o[t>>20&15]+o[t>>16&15]+o[t>>28&15]+o[t>>24&15]+o[e>>4&15]+o[15&e]+o[e>>12&15]+o[e>>8&15]+o[e>>20&15]+o[e>>16&15]+o[e>>28&15]+o[e>>24&15]+o[h>>4&15]+o[15&h]+o[h>>12&15]+o[h>>8&15]+o[h>>20&15]+o[h>>16&15]+o[h>>28&15]+o[h>>24&15]+o[r>>4&15]+o[15&r]+o[r>>12&15]+o[r>>8&15]+o[r>>20&15]+o[r>>16&15]+o[r>>28&15]+o[r>>24&15]},e.prototype.toString=e.prototype.hex,e.prototype.digest=function(){this.finalize();var t=this.h0,e=this.h1,h=this.h2,r=this.h3;return[255&t,t>>8&255,t>>16&255,t>>24&255,255&e,e>>8&255,e>>16&255,e>>24&255,255&h,h>>8&255,h>>16&255,h>>24&255,255&r,r>>8&255,r>>16&255,r>>24&255]},e.prototype.array=e.prototype.digest,e.prototype.buffer=function(){this.finalize();var t=new ArrayBuffer(16),e=new Uint32Array(t);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,t};var b=y();i?module.exports=b:(t.md5=b,s&&define(function(){return b}))}(this); |
@@ -0,1 +1,8 @@ | ||
# v0.4.0 / 2015-12-28 | ||
* Added support for update hash. | ||
* Added support for bytes array output. | ||
* Added support for ArrayBuffer output. | ||
* Added support for AMD. | ||
# v0.3.0 / 2015-03-07 | ||
@@ -2,0 +9,0 @@ |
@@ -1,2 +0,2 @@ | ||
Copyright 2014-2015 emn178@gmail.com | ||
Copyright 2014-2015 Yi-Cyuan Chen | ||
@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
{ | ||
"name": "js-md5", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.", | ||
@@ -8,7 +8,15 @@ "main": "src/md5.js", | ||
"expect.js": "~0.3.1", | ||
"jscoverage": "~0.5.9" | ||
"jscoverage": "~0.5.9", | ||
"jsdoc": "^3.4.0", | ||
"mocha": "~2.3.4", | ||
"requirejs": "^2.1.22", | ||
"uglifyjs": "~2.4.10" | ||
}, | ||
"scripts": { | ||
"test": "mocha tests/node-test.js -r jscoverage", | ||
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls" | ||
"report": "mocha tests/node-test.js -r jscoverage --covout=html", | ||
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls", | ||
"doc": "rm -rf doc;jsdoc src README.md -d doc", | ||
"compress": "uglifyjs src/md5.js --compress --mangle --comments --output build/md5.min.js", | ||
"build": "npm run-script compress;npm run-script doc" | ||
}, | ||
@@ -15,0 +23,0 @@ "repository": { |
@@ -9,2 +9,3 @@ # js-md5 | ||
[MD5 Online](http://emn178.github.io/online-tools/md5.html) | ||
[MD5 File Checksum Online](http://emn178.github.io/online-tools/md5_checksum.html) | ||
@@ -28,2 +29,5 @@ ## Download | ||
md5('Message to hash'); | ||
var hash = md5.create(); | ||
hash.update('Message to hash'); | ||
hash.hex(); | ||
``` | ||
@@ -34,38 +38,31 @@ If you use node.js, you should require the module first: | ||
``` | ||
## Example | ||
Code | ||
It supports AMD: | ||
```JavaScript | ||
md5(''); | ||
md5('The quick brown fox jumps over the lazy dog'); | ||
md5('The quick brown fox jumps over the lazy dog.'); | ||
require(['your/path/md5.js'], function(md5) { | ||
// ... | ||
}); | ||
``` | ||
Output | ||
[See document](https://emn178.github.com/js-md5/doc/) | ||
d41d8cd98f00b204e9800998ecf8427e | ||
9e107d9d372bb6826bd81d3542a419d6 | ||
e4d909c290d0fb1ca068ffaddf22cbd0 | ||
It also supports UTF-8 encoding: | ||
Code | ||
## Example | ||
```JavaScript | ||
md5('中文'); | ||
``` | ||
Output | ||
md5(''); // d41d8cd98f00b204e9800998ecf8427e | ||
md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6 | ||
md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0 | ||
a7bac2239fcdcb3a067903d8077c4a07 | ||
// It also supports UTF-8 encoding | ||
md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07 | ||
It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` input: | ||
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` | ||
md5([]); // d41d8cd98f00b204e9800998ecf8427e | ||
md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e | ||
Code | ||
```JavaScript | ||
md5([]); | ||
md5(new Uint8Array([])); | ||
// Different output | ||
md5(''); // d41d8cd98f00b204e9800998ecf8427e | ||
md5.hex(''); // d41d8cd98f00b204e9800998ecf8427e | ||
md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126] | ||
md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126] | ||
md5.buffer(''); // ArrayBuffer | ||
``` | ||
Output | ||
d41d8cd98f00b204e9800998ecf8427e | ||
d41d8cd98f00b204e9800998ecf8427e | ||
## Benchmark | ||
@@ -75,27 +72,2 @@ [UTF8](http://jsperf.com/md5-shootout/81) | ||
## Extensions | ||
### jQuery | ||
If you prefer jQuery style, you can add following code to add a jQuery extension. | ||
Code | ||
```JavaScript | ||
jQuery.md5 = md5 | ||
``` | ||
And then you could use like this: | ||
```JavaScript | ||
$.md5('message'); | ||
``` | ||
### Prototype | ||
If you prefer prototype style, you can add following code to add a prototype extension. | ||
Code | ||
```JavaScript | ||
String.prototype.md5 = function() { | ||
return md5(this); | ||
}; | ||
``` | ||
And then you could use like this: | ||
```JavaScript | ||
'message'.md5(); | ||
``` | ||
## License | ||
@@ -106,2 +78,2 @@ The project is released under the [MIT license](http://www.opensource.org/licenses/MIT). | ||
The project's website is located at https://github.com/emn178/js-md5 | ||
Author: emn178@gmail.com | ||
Author: Yi-Cyuan Chen (emn178@gmail.com) |
782
src/md5.js
@@ -1,28 +0,27 @@ | ||
/* | ||
* js-md5 v0.3.0 | ||
* https://github.com/emn178/js-md5 | ||
/** | ||
* [js-md5]{@link https://github.com/emn178/js-md5} | ||
* | ||
* Copyright 2014-2015, emn178@gmail.com | ||
* | ||
* Licensed under the MIT license: | ||
* http://www.opensource.org/licenses/MIT | ||
* @namespace md5 | ||
* @version 0.4.0 | ||
* @author Yi-Cyuan Chen [emn178@gmail.com] | ||
* @copyright Yi-Cyuan Chen 2014-2015 | ||
* @license MIT | ||
*/ | ||
;(function(root, undefined) { | ||
(function (root) { | ||
'use strict'; | ||
var NODE_JS = typeof(module) != 'undefined'; | ||
if(NODE_JS) { | ||
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node; | ||
if (NODE_JS) { | ||
root = global; | ||
if(root.JS_MD5_TEST) { | ||
root.navigator = { userAgent: 'Firefox'}; | ||
} | ||
} | ||
var FIREFOX = (root.JS_MD5_TEST || !NODE_JS) && navigator.userAgent.indexOf('Firefox') != -1; | ||
var ARRAY_BUFFER = !root.JS_MD5_TEST && typeof(ArrayBuffer) != 'undefined'; | ||
var COMMON_JS = !root.JS_MD5_TEST && typeof module == 'object' && module.exports; | ||
var AMD = typeof define == 'function' && define.amd; | ||
var ARRAY_BUFFER = !root.JS_MD5_TEST && typeof ArrayBuffer != 'undefined'; | ||
var HEX_CHARS = '0123456789abcdef'.split(''); | ||
var EXTRA = [128, 32768, 8388608, -2147483648]; | ||
var SHIFT = [0, 8, 16, 24]; | ||
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer']; | ||
var blocks = [], buffer8; | ||
if(ARRAY_BUFFER) { | ||
if (ARRAY_BUFFER) { | ||
var buffer = new ArrayBuffer(68); | ||
@@ -33,24 +32,203 @@ buffer8 = new Uint8Array(buffer); | ||
var md5 = function(message) { | ||
var notString = typeof(message) != 'string'; | ||
if(notString && message.constructor == ArrayBuffer) { | ||
message = new Uint8Array(message); | ||
/** | ||
* @method hex | ||
* @memberof md5 | ||
* @description Output hash as hex string | ||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash | ||
* @returns {String} Hex string | ||
* @example | ||
* md5.hex('The quick brown fox jumps over the lazy dog'); | ||
* // equal to | ||
* md5('The quick brown fox jumps over the lazy dog'); | ||
*/ | ||
/** | ||
* @method digest | ||
* @memberof md5 | ||
* @description Output hash as bytes array | ||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash | ||
* @returns {Array} Bytes array | ||
* @example | ||
* md5.digest('The quick brown fox jumps over the lazy dog'); | ||
*/ | ||
/** | ||
* @method array | ||
* @memberof md5 | ||
* @description Output hash as bytes array | ||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash | ||
* @returns {Array} Bytes array | ||
* @example | ||
* md5.array('The quick brown fox jumps over the lazy dog'); | ||
*/ | ||
/** | ||
* @method buffer | ||
* @memberof md5 | ||
* @description Output hash as ArrayBuffer | ||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash | ||
* @returns {ArrayBuffer} ArrayBuffer | ||
* @example | ||
* md5.buffer('The quick brown fox jumps over the lazy dog'); | ||
*/ | ||
var createOutputMethod = function (outputType) { | ||
return function(message) { | ||
return new Md5(true).update(message)[outputType](); | ||
}; | ||
}; | ||
/** | ||
* @method create | ||
* @memberof md5 | ||
* @description Create Md5 object | ||
* @returns {Md5} Md5 object. | ||
* @example | ||
* var hash = md5.create(); | ||
*/ | ||
/** | ||
* @method update | ||
* @memberof md5 | ||
* @description Create and update Md5 object | ||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash | ||
* @returns {Md5} Md5 object. | ||
* @example | ||
* var hash = md5.update('The quick brown fox jumps over the lazy dog'); | ||
* // equal to | ||
* var hash = md5.create(); | ||
* hash.update('The quick brown fox jumps over the lazy dog'); | ||
*/ | ||
var createMethod = function () { | ||
var method = createOutputMethod('hex'); | ||
if (NODE_JS) { | ||
method = nodeWrap(method); | ||
} | ||
method.create = function () { | ||
return new Md5(); | ||
}; | ||
method.update = function (message) { | ||
return method.create().update(message); | ||
}; | ||
for (var i = 0;i < OUTPUT_TYPES.length;++i) { | ||
var type = OUTPUT_TYPES[i]; | ||
method[type] = createOutputMethod(type); | ||
} | ||
return method; | ||
}; | ||
var h0, h1, h2, h3, a, b, c, d, bc, da, code, first = true, end = false, | ||
index = 0, i, start = 0, bytes = 0, length = message.length; | ||
blocks[16] = 0; | ||
do { | ||
blocks[0] = blocks[16]; | ||
blocks[16] = blocks[1] = blocks[2] = blocks[3] = | ||
var nodeWrap = function (method) { | ||
var crypto, Buffer; | ||
try { | ||
if (root.JS_MD5_TEST) { | ||
throw 'JS_MD5_TEST'; | ||
} | ||
crypto = require('crypto'); | ||
Buffer = require('buffer').Buffer; | ||
} catch (e) { | ||
console.log(e); | ||
return method; | ||
} | ||
var nodeMethod = function (message) { | ||
if (typeof message == 'string') { | ||
if (message.length <= nodeMethod.utf8Threshold) { | ||
return method(message); | ||
} else if (message.length <= nodeMethod.asciiThreshold && !/[^\x00-\x7F]/.test(message)) { | ||
return method(message); | ||
} | ||
return crypto.createHash('md5').update(message, 'utf8').digest('hex'); | ||
} else if (message.constructor == ArrayBuffer) { | ||
message = new Uint8Array(message); | ||
} else if (message.length === undefined || message.length <= nodeMethod.bytesThreshold) { | ||
return method(message); | ||
} | ||
return crypto.createHash('md5').update(new Buffer(message)).digest('hex'); | ||
}; | ||
/** | ||
* @member {Number} utf8Threshold | ||
* @default 18 | ||
* @description To use node.js md5 if UTF-8 string length is greater than this value. | ||
* @memberof md5 | ||
*/ | ||
nodeMethod.utf8Threshold = 18; | ||
/** | ||
* @member {Number} asciiThreshold | ||
* @default 60 | ||
* @description To use node.js md5 if ascii string length is greater than this value. | ||
* @memberof md5 | ||
*/ | ||
nodeMethod.asciiThreshold = 60; | ||
/** | ||
* @member {Number} bytesThreshold | ||
* @default 245 | ||
* @description To use node.js md5 if bytes length is greater than this value. | ||
* @memberof md5 | ||
*/ | ||
nodeMethod.bytesThreshold = 245; | ||
return nodeMethod; | ||
}; | ||
/** | ||
* Md5 class | ||
* @class Md5 | ||
* @description This is internal class. | ||
* @see {@link md5.create} | ||
*/ | ||
function Md5(sharedMemory) { | ||
if (sharedMemory) { | ||
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = | ||
blocks[4] = blocks[5] = blocks[6] = blocks[7] = | ||
blocks[8] = blocks[9] = blocks[10] = blocks[11] = | ||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
if(notString) { | ||
if(ARRAY_BUFFER) { | ||
for (i = start;index < length && i < 64; ++index) { | ||
this.blocks = blocks; | ||
this.buffer8 = buffer8; | ||
} else { | ||
if (ARRAY_BUFFER) { | ||
var buffer = new ArrayBuffer(68); | ||
this.buffer8 = new Uint8Array(buffer); | ||
this.blocks = new Uint32Array(buffer); | ||
} else { | ||
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
} | ||
} | ||
this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = 0; | ||
this.finalized = this.hashed = false; | ||
this.first = true; | ||
} | ||
/** | ||
* @method update | ||
* @memberof Md5 | ||
* @instance | ||
* @description Update hash | ||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash | ||
* @returns {Md5} Md5 object. | ||
* @see {@link md5.update} | ||
*/ | ||
Md5.prototype.update = function (message) { | ||
if (this.finalized) { | ||
return; | ||
} | ||
var notString = typeof(message) != 'string'; | ||
if(notString && message.constructor == root.ArrayBuffer) { | ||
message = new Uint8Array(message); | ||
} | ||
var code, index = 0, i, length = message.length || 0, blocks = this.blocks; | ||
var buffer8 = this.buffer8; | ||
while (index < length) { | ||
if (this.hashed) { | ||
this.hashed = false; | ||
blocks[0] = blocks[16]; | ||
blocks[16] = blocks[1] = blocks[2] = blocks[3] = | ||
blocks[4] = blocks[5] = blocks[6] = blocks[7] = | ||
blocks[8] = blocks[9] = blocks[10] = blocks[11] = | ||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
} | ||
if (notString) { | ||
if (ARRAY_BUFFER) { | ||
for (i = this.start;index < length && i < 64; ++index) { | ||
buffer8[i++] = message[index]; | ||
} | ||
} else { | ||
for (i = start;index < length && i < 64; ++index) { | ||
for (i = this.start;index < length && i < 64; ++index) { | ||
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; | ||
@@ -60,4 +238,4 @@ } | ||
} else { | ||
if(ARRAY_BUFFER) { | ||
for (i = start;index < length && i < 64; ++index) { | ||
if (ARRAY_BUFFER) { | ||
for (i = this.start;index < length && i < 64; ++index) { | ||
code = message.charCodeAt(index); | ||
@@ -82,3 +260,3 @@ if (code < 0x80) { | ||
} else { | ||
for (i = start;index < length && i < 64; ++index) { | ||
for (i = this.start;index < length && i < 64; ++index) { | ||
code = message.charCodeAt(index); | ||
@@ -104,242 +282,336 @@ if (code < 0x80) { | ||
} | ||
bytes += i - start; | ||
start = i - 64; | ||
if(index == length) { | ||
blocks[i >> 2] |= EXTRA[i & 3]; | ||
++index; | ||
} | ||
if(index > length && i < 56) { | ||
blocks[14] = bytes << 3; | ||
end = true; | ||
} | ||
if(first) { | ||
a = blocks[0] - 680876937; | ||
a = (a << 7 | a >>> 25) - 271733879 << 0; | ||
d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708; | ||
d = (d << 12 | d >>> 20) + a << 0; | ||
c = (-271733879 ^ (d & (a ^ -271733879))) + blocks[2] - 1126478375; | ||
c = (c << 17 | c >>> 15) + d << 0; | ||
b = (a ^ (c & (d ^ a))) + blocks[3] - 1316259209; | ||
b = (b << 22 | b >>> 10) + c << 0; | ||
this.lastByteIndex = i; | ||
this.bytes += i - this.start; | ||
if (i >= 64) { | ||
this.start = i - 64; | ||
this.hash(); | ||
this.hashed = true; | ||
} else { | ||
a = h0; | ||
b = h1; | ||
c = h2; | ||
d = h3; | ||
a += (d ^ (b & (c ^ d))) + blocks[0] - 680876936; | ||
a = (a << 7 | a >>> 25) + b << 0; | ||
d += (c ^ (a & (b ^ c))) + blocks[1] - 389564586; | ||
d = (d << 12 | d >>> 20) + a << 0; | ||
c += (b ^ (d & (a ^ b))) + blocks[2] + 606105819; | ||
c = (c << 17 | c >>> 15) + d << 0; | ||
b += (a ^ (c & (d ^ a))) + blocks[3] - 1044525330; | ||
b = (b << 22 | b >>> 10) + c << 0; | ||
this.start = i; | ||
} | ||
} | ||
return this; | ||
}; | ||
a += (d ^ (b & (c ^ d))) + blocks[4] - 176418897; | ||
a = (a << 7 | a >>> 25) + b << 0; | ||
d += (c ^ (a & (b ^ c))) + blocks[5] + 1200080426; | ||
Md5.prototype.finalize = function () { | ||
if (this.finalized) { | ||
return; | ||
} | ||
this.finalized = true; | ||
var blocks = this.blocks, i = this.lastByteIndex; | ||
blocks[i >> 2] |= EXTRA[i & 3]; | ||
if (i >= 56) { | ||
if (!this.hashed) { | ||
this.hash(); | ||
} | ||
blocks[0] = blocks[16]; | ||
blocks[16] = blocks[1] = blocks[2] = blocks[3] = | ||
blocks[4] = blocks[5] = blocks[6] = blocks[7] = | ||
blocks[8] = blocks[9] = blocks[10] = blocks[11] = | ||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
} | ||
blocks[14] = this.bytes << 3; | ||
this.hash(); | ||
}; | ||
Md5.prototype.hash = function () { | ||
var a, b, c, d, bc, da, blocks = this.blocks; | ||
if(this.first) { | ||
a = blocks[0] - 680876937; | ||
a = (a << 7 | a >>> 25) - 271733879 << 0; | ||
d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708; | ||
d = (d << 12 | d >>> 20) + a << 0; | ||
c += (b ^ (d & (a ^ b))) + blocks[6] - 1473231341; | ||
c = (-271733879 ^ (d & (a ^ -271733879))) + blocks[2] - 1126478375; | ||
c = (c << 17 | c >>> 15) + d << 0; | ||
b += (a ^ (c & (d ^ a))) + blocks[7] - 45705983; | ||
b = (a ^ (c & (d ^ a))) + blocks[3] - 1316259209; | ||
b = (b << 22 | b >>> 10) + c << 0; | ||
a += (d ^ (b & (c ^ d))) + blocks[8] + 1770035416; | ||
} else { | ||
a = this.h0; | ||
b = this.h1; | ||
c = this.h2; | ||
d = this.h3; | ||
a += (d ^ (b & (c ^ d))) + blocks[0] - 680876936; | ||
a = (a << 7 | a >>> 25) + b << 0; | ||
d += (c ^ (a & (b ^ c))) + blocks[9] - 1958414417; | ||
d += (c ^ (a & (b ^ c))) + blocks[1] - 389564586; | ||
d = (d << 12 | d >>> 20) + a << 0; | ||
c += (b ^ (d & (a ^ b))) + blocks[10] - 42063; | ||
c += (b ^ (d & (a ^ b))) + blocks[2] + 606105819; | ||
c = (c << 17 | c >>> 15) + d << 0; | ||
b += (a ^ (c & (d ^ a))) + blocks[11] - 1990404162; | ||
b += (a ^ (c & (d ^ a))) + blocks[3] - 1044525330; | ||
b = (b << 22 | b >>> 10) + c << 0; | ||
a += (d ^ (b & (c ^ d))) + blocks[12] + 1804603682; | ||
a = (a << 7 | a >>> 25) + b << 0; | ||
d += (c ^ (a & (b ^ c))) + blocks[13] - 40341101; | ||
d = (d << 12 | d >>> 20) + a << 0; | ||
c += (b ^ (d & (a ^ b))) + blocks[14] - 1502002290; | ||
c = (c << 17 | c >>> 15) + d << 0; | ||
b += (a ^ (c & (d ^ a))) + blocks[15] + 1236535329; | ||
b = (b << 22 | b >>> 10) + c << 0; | ||
a += (c ^ (d & (b ^ c))) + blocks[1] - 165796510; | ||
a = (a << 5 | a >>> 27) + b << 0; | ||
d += (b ^ (c & (a ^ b))) + blocks[6] - 1069501632; | ||
d = (d << 9 | d >>> 23) + a << 0; | ||
c += (a ^ (b & (d ^ a))) + blocks[11] + 643717713; | ||
c = (c << 14 | c >>> 18) + d << 0; | ||
b += (d ^ (a & (c ^ d))) + blocks[0] - 373897302; | ||
b = (b << 20 | b >>> 12) + c << 0; | ||
a += (c ^ (d & (b ^ c))) + blocks[5] - 701558691; | ||
a = (a << 5 | a >>> 27) + b << 0; | ||
d += (b ^ (c & (a ^ b))) + blocks[10] + 38016083; | ||
d = (d << 9 | d >>> 23) + a << 0; | ||
c += (a ^ (b & (d ^ a))) + blocks[15] - 660478335; | ||
c = (c << 14 | c >>> 18) + d << 0; | ||
b += (d ^ (a & (c ^ d))) + blocks[4] - 405537848; | ||
b = (b << 20 | b >>> 12) + c << 0; | ||
a += (c ^ (d & (b ^ c))) + blocks[9] + 568446438; | ||
a = (a << 5 | a >>> 27) + b << 0; | ||
d += (b ^ (c & (a ^ b))) + blocks[14] - 1019803690; | ||
d = (d << 9 | d >>> 23) + a << 0; | ||
c += (a ^ (b & (d ^ a))) + blocks[3] - 187363961; | ||
c = (c << 14 | c >>> 18) + d << 0; | ||
b += (d ^ (a & (c ^ d))) + blocks[8] + 1163531501; | ||
b = (b << 20 | b >>> 12) + c << 0; | ||
a += (c ^ (d & (b ^ c))) + blocks[13] - 1444681467; | ||
a = (a << 5 | a >>> 27) + b << 0; | ||
d += (b ^ (c & (a ^ b))) + blocks[2] - 51403784; | ||
d = (d << 9 | d >>> 23) + a << 0; | ||
c += (a ^ (b & (d ^ a))) + blocks[7] + 1735328473; | ||
c = (c << 14 | c >>> 18) + d << 0; | ||
b += (d ^ (a & (c ^ d))) + blocks[12] - 1926607734; | ||
b = (b << 20 | b >>> 12) + c << 0; | ||
bc = b ^ c; | ||
a += (bc ^ d) + blocks[5] - 378558; | ||
a = (a << 4 | a >>> 28) + b << 0; | ||
d += (bc ^ a) + blocks[8] - 2022574463; | ||
d = (d << 11 | d >>> 21) + a << 0; | ||
da = d ^ a; | ||
c += (da ^ b) + blocks[11] + 1839030562; | ||
c = (c << 16 | c >>> 16) + d << 0; | ||
b += (da ^ c) + blocks[14] - 35309556; | ||
b = (b << 23 | b >>> 9) + c << 0; | ||
bc = b ^ c; | ||
a += (bc ^ d) + blocks[1] - 1530992060; | ||
a = (a << 4 | a >>> 28) + b << 0; | ||
d += (bc ^ a) + blocks[4] + 1272893353; | ||
d = (d << 11 | d >>> 21) + a << 0; | ||
da = d ^ a; | ||
c += (da ^ b) + blocks[7] - 155497632; | ||
c = (c << 16 | c >>> 16) + d << 0; | ||
b += (da ^ c) + blocks[10] - 1094730640; | ||
b = (b << 23 | b >>> 9) + c << 0; | ||
bc = b ^ c; | ||
a += (bc ^ d) + blocks[13] + 681279174; | ||
a = (a << 4 | a >>> 28) + b << 0; | ||
d += (bc ^ a) + blocks[0] - 358537222; | ||
d = (d << 11 | d >>> 21) + a << 0; | ||
da = d ^ a; | ||
c += (da ^ b) + blocks[3] - 722521979; | ||
c = (c << 16 | c >>> 16) + d << 0; | ||
b += (da ^ c) + blocks[6] + 76029189; | ||
b = (b << 23 | b >>> 9) + c << 0; | ||
bc = b ^ c; | ||
a += (bc ^ d) + blocks[9] - 640364487; | ||
a = (a << 4 | a >>> 28) + b << 0; | ||
d += (bc ^ a) + blocks[12] - 421815835; | ||
d = (d << 11 | d >>> 21) + a << 0; | ||
da = d ^ a; | ||
c += (da ^ b) + blocks[15] + 530742520; | ||
c = (c << 16 | c >>> 16) + d << 0; | ||
b += (da ^ c) + blocks[2] - 995338651; | ||
b = (b << 23 | b >>> 9) + c << 0; | ||
a += (c ^ (b | ~d)) + blocks[0] - 198630844; | ||
a = (a << 6 | a >>> 26) + b << 0; | ||
d += (b ^ (a | ~c)) + blocks[7] + 1126891415; | ||
d = (d << 10 | d >>> 22) + a << 0; | ||
c += (a ^ (d | ~b)) + blocks[14] - 1416354905; | ||
c = (c << 15 | c >>> 17) + d << 0; | ||
b += (d ^ (c | ~a)) + blocks[5] - 57434055; | ||
b = (b << 21 | b >>> 11) + c << 0; | ||
a += (c ^ (b | ~d)) + blocks[12] + 1700485571; | ||
a = (a << 6 | a >>> 26) + b << 0; | ||
d += (b ^ (a | ~c)) + blocks[3] - 1894986606; | ||
d = (d << 10 | d >>> 22) + a << 0; | ||
c += (a ^ (d | ~b)) + blocks[10] - 1051523; | ||
c = (c << 15 | c >>> 17) + d << 0; | ||
b += (d ^ (c | ~a)) + blocks[1] - 2054922799; | ||
b = (b << 21 | b >>> 11) + c << 0; | ||
a += (c ^ (b | ~d)) + blocks[8] + 1873313359; | ||
a = (a << 6 | a >>> 26) + b << 0; | ||
d += (b ^ (a | ~c)) + blocks[15] - 30611744; | ||
d = (d << 10 | d >>> 22) + a << 0; | ||
c += (a ^ (d | ~b)) + blocks[6] - 1560198380; | ||
c = (c << 15 | c >>> 17) + d << 0; | ||
b += (d ^ (c | ~a)) + blocks[13] + 1309151649; | ||
b = (b << 21 | b >>> 11) + c << 0; | ||
a += (c ^ (b | ~d)) + blocks[4] - 145523070; | ||
a = (a << 6 | a >>> 26) + b << 0; | ||
d += (b ^ (a | ~c)) + blocks[11] - 1120210379; | ||
d = (d << 10 | d >>> 22) + a << 0; | ||
c += (a ^ (d | ~b)) + blocks[2] + 718787259; | ||
c = (c << 15 | c >>> 17) + d << 0; | ||
b += (d ^ (c | ~a)) + blocks[9] - 343485551; | ||
b = (b << 21 | b >>> 11) + c << 0; | ||
} | ||
if(first) { | ||
h0 = a + 1732584193 << 0; | ||
h1 = b - 271733879 << 0; | ||
h2 = c - 1732584194 << 0; | ||
h3 = d + 271733878 << 0; | ||
first = false; | ||
} else { | ||
h0 = h0 + a << 0; | ||
h1 = h1 + b << 0; | ||
h2 = h2 + c << 0; | ||
h3 = h3 + d << 0; | ||
} | ||
} while(!end); | ||
a += (d ^ (b & (c ^ d))) + blocks[4] - 176418897; | ||
a = (a << 7 | a >>> 25) + b << 0; | ||
d += (c ^ (a & (b ^ c))) + blocks[5] + 1200080426; | ||
d = (d << 12 | d >>> 20) + a << 0; | ||
c += (b ^ (d & (a ^ b))) + blocks[6] - 1473231341; | ||
c = (c << 17 | c >>> 15) + d << 0; | ||
b += (a ^ (c & (d ^ a))) + blocks[7] - 45705983; | ||
b = (b << 22 | b >>> 10) + c << 0; | ||
a += (d ^ (b & (c ^ d))) + blocks[8] + 1770035416; | ||
a = (a << 7 | a >>> 25) + b << 0; | ||
d += (c ^ (a & (b ^ c))) + blocks[9] - 1958414417; | ||
d = (d << 12 | d >>> 20) + a << 0; | ||
c += (b ^ (d & (a ^ b))) + blocks[10] - 42063; | ||
c = (c << 17 | c >>> 15) + d << 0; | ||
b += (a ^ (c & (d ^ a))) + blocks[11] - 1990404162; | ||
b = (b << 22 | b >>> 10) + c << 0; | ||
a += (d ^ (b & (c ^ d))) + blocks[12] + 1804603682; | ||
a = (a << 7 | a >>> 25) + b << 0; | ||
d += (c ^ (a & (b ^ c))) + blocks[13] - 40341101; | ||
d = (d << 12 | d >>> 20) + a << 0; | ||
c += (b ^ (d & (a ^ b))) + blocks[14] - 1502002290; | ||
c = (c << 17 | c >>> 15) + d << 0; | ||
b += (a ^ (c & (d ^ a))) + blocks[15] + 1236535329; | ||
b = (b << 22 | b >>> 10) + c << 0; | ||
a += (c ^ (d & (b ^ c))) + blocks[1] - 165796510; | ||
a = (a << 5 | a >>> 27) + b << 0; | ||
d += (b ^ (c & (a ^ b))) + blocks[6] - 1069501632; | ||
d = (d << 9 | d >>> 23) + a << 0; | ||
c += (a ^ (b & (d ^ a))) + blocks[11] + 643717713; | ||
c = (c << 14 | c >>> 18) + d << 0; | ||
b += (d ^ (a & (c ^ d))) + blocks[0] - 373897302; | ||
b = (b << 20 | b >>> 12) + c << 0; | ||
a += (c ^ (d & (b ^ c))) + blocks[5] - 701558691; | ||
a = (a << 5 | a >>> 27) + b << 0; | ||
d += (b ^ (c & (a ^ b))) + blocks[10] + 38016083; | ||
d = (d << 9 | d >>> 23) + a << 0; | ||
c += (a ^ (b & (d ^ a))) + blocks[15] - 660478335; | ||
c = (c << 14 | c >>> 18) + d << 0; | ||
b += (d ^ (a & (c ^ d))) + blocks[4] - 405537848; | ||
b = (b << 20 | b >>> 12) + c << 0; | ||
a += (c ^ (d & (b ^ c))) + blocks[9] + 568446438; | ||
a = (a << 5 | a >>> 27) + b << 0; | ||
d += (b ^ (c & (a ^ b))) + blocks[14] - 1019803690; | ||
d = (d << 9 | d >>> 23) + a << 0; | ||
c += (a ^ (b & (d ^ a))) + blocks[3] - 187363961; | ||
c = (c << 14 | c >>> 18) + d << 0; | ||
b += (d ^ (a & (c ^ d))) + blocks[8] + 1163531501; | ||
b = (b << 20 | b >>> 12) + c << 0; | ||
a += (c ^ (d & (b ^ c))) + blocks[13] - 1444681467; | ||
a = (a << 5 | a >>> 27) + b << 0; | ||
d += (b ^ (c & (a ^ b))) + blocks[2] - 51403784; | ||
d = (d << 9 | d >>> 23) + a << 0; | ||
c += (a ^ (b & (d ^ a))) + blocks[7] + 1735328473; | ||
c = (c << 14 | c >>> 18) + d << 0; | ||
b += (d ^ (a & (c ^ d))) + blocks[12] - 1926607734; | ||
b = (b << 20 | b >>> 12) + c << 0; | ||
bc = b ^ c; | ||
a += (bc ^ d) + blocks[5] - 378558; | ||
a = (a << 4 | a >>> 28) + b << 0; | ||
d += (bc ^ a) + blocks[8] - 2022574463; | ||
d = (d << 11 | d >>> 21) + a << 0; | ||
da = d ^ a; | ||
c += (da ^ b) + blocks[11] + 1839030562; | ||
c = (c << 16 | c >>> 16) + d << 0; | ||
b += (da ^ c) + blocks[14] - 35309556; | ||
b = (b << 23 | b >>> 9) + c << 0; | ||
bc = b ^ c; | ||
a += (bc ^ d) + blocks[1] - 1530992060; | ||
a = (a << 4 | a >>> 28) + b << 0; | ||
d += (bc ^ a) + blocks[4] + 1272893353; | ||
d = (d << 11 | d >>> 21) + a << 0; | ||
da = d ^ a; | ||
c += (da ^ b) + blocks[7] - 155497632; | ||
c = (c << 16 | c >>> 16) + d << 0; | ||
b += (da ^ c) + blocks[10] - 1094730640; | ||
b = (b << 23 | b >>> 9) + c << 0; | ||
bc = b ^ c; | ||
a += (bc ^ d) + blocks[13] + 681279174; | ||
a = (a << 4 | a >>> 28) + b << 0; | ||
d += (bc ^ a) + blocks[0] - 358537222; | ||
d = (d << 11 | d >>> 21) + a << 0; | ||
da = d ^ a; | ||
c += (da ^ b) + blocks[3] - 722521979; | ||
c = (c << 16 | c >>> 16) + d << 0; | ||
b += (da ^ c) + blocks[6] + 76029189; | ||
b = (b << 23 | b >>> 9) + c << 0; | ||
bc = b ^ c; | ||
a += (bc ^ d) + blocks[9] - 640364487; | ||
a = (a << 4 | a >>> 28) + b << 0; | ||
d += (bc ^ a) + blocks[12] - 421815835; | ||
d = (d << 11 | d >>> 21) + a << 0; | ||
da = d ^ a; | ||
c += (da ^ b) + blocks[15] + 530742520; | ||
c = (c << 16 | c >>> 16) + d << 0; | ||
b += (da ^ c) + blocks[2] - 995338651; | ||
b = (b << 23 | b >>> 9) + c << 0; | ||
a += (c ^ (b | ~d)) + blocks[0] - 198630844; | ||
a = (a << 6 | a >>> 26) + b << 0; | ||
d += (b ^ (a | ~c)) + blocks[7] + 1126891415; | ||
d = (d << 10 | d >>> 22) + a << 0; | ||
c += (a ^ (d | ~b)) + blocks[14] - 1416354905; | ||
c = (c << 15 | c >>> 17) + d << 0; | ||
b += (d ^ (c | ~a)) + blocks[5] - 57434055; | ||
b = (b << 21 | b >>> 11) + c << 0; | ||
a += (c ^ (b | ~d)) + blocks[12] + 1700485571; | ||
a = (a << 6 | a >>> 26) + b << 0; | ||
d += (b ^ (a | ~c)) + blocks[3] - 1894986606; | ||
d = (d << 10 | d >>> 22) + a << 0; | ||
c += (a ^ (d | ~b)) + blocks[10] - 1051523; | ||
c = (c << 15 | c >>> 17) + d << 0; | ||
b += (d ^ (c | ~a)) + blocks[1] - 2054922799; | ||
b = (b << 21 | b >>> 11) + c << 0; | ||
a += (c ^ (b | ~d)) + blocks[8] + 1873313359; | ||
a = (a << 6 | a >>> 26) + b << 0; | ||
d += (b ^ (a | ~c)) + blocks[15] - 30611744; | ||
d = (d << 10 | d >>> 22) + a << 0; | ||
c += (a ^ (d | ~b)) + blocks[6] - 1560198380; | ||
c = (c << 15 | c >>> 17) + d << 0; | ||
b += (d ^ (c | ~a)) + blocks[13] + 1309151649; | ||
b = (b << 21 | b >>> 11) + c << 0; | ||
a += (c ^ (b | ~d)) + blocks[4] - 145523070; | ||
a = (a << 6 | a >>> 26) + b << 0; | ||
d += (b ^ (a | ~c)) + blocks[11] - 1120210379; | ||
d = (d << 10 | d >>> 22) + a << 0; | ||
c += (a ^ (d | ~b)) + blocks[2] + 718787259; | ||
c = (c << 15 | c >>> 17) + d << 0; | ||
b += (d ^ (c | ~a)) + blocks[9] - 343485551; | ||
b = (b << 21 | b >>> 11) + c << 0; | ||
if(FIREFOX) { | ||
var hex = HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F]; | ||
hex += HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F]; | ||
hex += HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F]; | ||
hex += HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F]; | ||
hex += HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F]; | ||
hex += HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F]; | ||
hex += HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F]; | ||
hex += HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F]; | ||
hex += HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F]; | ||
hex += HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F]; | ||
hex += HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F]; | ||
hex += HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F]; | ||
hex += HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F]; | ||
hex += HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F]; | ||
hex += HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F]; | ||
hex += HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F]; | ||
return hex; | ||
if(this.first) { | ||
this.h0 = a + 1732584193 << 0; | ||
this.h1 = b - 271733879 << 0; | ||
this.h2 = c - 1732584194 << 0; | ||
this.h3 = d + 271733878 << 0; | ||
this.first = false; | ||
} else { | ||
return HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] + | ||
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] + | ||
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] + | ||
HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + | ||
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + | ||
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] + | ||
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] + | ||
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] + | ||
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + | ||
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] + | ||
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] + | ||
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] + | ||
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + | ||
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] + | ||
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] + | ||
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F]; | ||
this.h0 = this.h0 + a << 0; | ||
this.h1 = this.h1 + b << 0; | ||
this.h2 = this.h2 + c << 0; | ||
this.h3 = this.h3 + d << 0; | ||
} | ||
}; | ||
if(!root.JS_MD5_TEST && NODE_JS) { | ||
var crypto = require('crypto'); | ||
var Buffer = require('buffer').Buffer; | ||
/** | ||
* @method hex | ||
* @memberof Md5 | ||
* @instance | ||
* @description Output hash as hex string | ||
* @returns {String} Hex string | ||
* @see {@link md5.hex} | ||
* @example | ||
* hash.hex(); | ||
*/ | ||
Md5.prototype.hex = function () { | ||
this.finalize(); | ||
module.exports = function(message) { | ||
if(typeof(message) == 'string') { | ||
if(message.length <= 80) { | ||
return md5(message); | ||
} else if(message.length <= 183 && !/[^\x00-\x7F]/.test(message)) { | ||
return md5(message); | ||
} | ||
return crypto.createHash('md5').update(message, 'utf8').digest('hex'); | ||
} | ||
if(message.constructor == ArrayBuffer) { | ||
message = new Uint8Array(message); | ||
} | ||
if(message.length <= 370) { | ||
return md5(message); | ||
} | ||
return crypto.createHash('md5').update(new Buffer(message)).digest('hex'); | ||
}; | ||
} else if(root) { | ||
root.md5 = md5; | ||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3; | ||
return HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] + | ||
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] + | ||
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] + | ||
HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + | ||
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + | ||
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] + | ||
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] + | ||
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] + | ||
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + | ||
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] + | ||
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] + | ||
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] + | ||
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + | ||
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] + | ||
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] + | ||
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F]; | ||
}; | ||
/** | ||
* @method toString | ||
* @memberof Md5 | ||
* @instance | ||
* @description Output hash as hex string | ||
* @returns {String} Hex string | ||
* @see {@link md5.hex} | ||
* @example | ||
* hash.toString(); | ||
*/ | ||
Md5.prototype.toString = Md5.prototype.hex; | ||
/** | ||
* @method digest | ||
* @memberof Md5 | ||
* @instance | ||
* @description Output hash as bytes array | ||
* @returns {Array} Bytes array | ||
* @see {@link md5.digest} | ||
* @example | ||
* hash.digest(); | ||
*/ | ||
Md5.prototype.digest = function() { | ||
this.finalize(); | ||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3; | ||
return [ | ||
h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 24) & 0xFF, | ||
h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 24) & 0xFF, | ||
h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 24) & 0xFF, | ||
h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 24) & 0xFF | ||
]; | ||
}; | ||
/** | ||
* @method array | ||
* @memberof Md5 | ||
* @instance | ||
* @description Output hash as bytes array | ||
* @returns {Array} Bytes array | ||
* @see {@link md5.array} | ||
* @example | ||
* hash.array(); | ||
*/ | ||
Md5.prototype.array = Md5.prototype.digest; | ||
/** | ||
* @method buffer | ||
* @memberof Md5 | ||
* @instance | ||
* @description Output hash as ArrayBuffer | ||
* @returns {ArrayBuffer} ArrayBuffer | ||
* @see {@link md5.buffer} | ||
* @example | ||
* hash.buffer(); | ||
*/ | ||
Md5.prototype.buffer = function() { | ||
this.finalize(); | ||
var buffer = new ArrayBuffer(16); | ||
var blocks = new Uint32Array(buffer); | ||
blocks[0] = this.h0; | ||
blocks[1] = this.h1; | ||
blocks[2] = this.h2; | ||
blocks[3] = this.h3; | ||
return buffer; | ||
}; | ||
var exports = createMethod(); | ||
if (COMMON_JS) { | ||
module.exports = exports; | ||
} else { | ||
/** | ||
* @method md5 | ||
* @description Md5 hash function, export to global in browsers. | ||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash | ||
* @returns {String} md5 hashes | ||
* @example | ||
* md5(''); // d41d8cd98f00b204e9800998ecf8427e | ||
* md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6 | ||
* md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0 | ||
* | ||
* // It also supports UTF-8 encoding | ||
* md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07 | ||
* | ||
* // It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` | ||
* md5([]); // d41d8cd98f00b204e9800998ecf8427e | ||
* md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e | ||
*/ | ||
root.md5 = exports; | ||
if (AMD) { | ||
define(function () { | ||
return exports; | ||
}); | ||
} | ||
} | ||
}(this)); |
@@ -12,1 +12,13 @@ md5 = require('../src/md5.js'); | ||
require('./test.js'); | ||
delete require.cache[require.resolve('../src/md5.js')]; | ||
delete require.cache[require.resolve('./test.js')]; | ||
md5 = null; | ||
define = function(func) { | ||
md5 = func(); | ||
require('./test.js'); | ||
}; | ||
define.amd = true; | ||
require('../src/md5.js'); |
@@ -1,71 +0,246 @@ | ||
(function(md5) { | ||
describe('md5', function() { | ||
describe('ascii', function() { | ||
describe('less than 64 bytes', function() { | ||
it('should be successful', function() { | ||
expect(md5('')).to.be('d41d8cd98f00b204e9800998ecf8427e'); | ||
expect(md5('The quick brown fox jumps over the lazy dog')).to.be('9e107d9d372bb6826bd81d3542a419d6'); | ||
expect(md5('The quick brown fox jumps over the lazy dog.')).to.be('e4d909c290d0fb1ca068ffaddf22cbd0'); | ||
}); | ||
}); | ||
(function (md5) { | ||
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () { | ||
var array = new Uint8Array(this); | ||
var hex = ''; | ||
for (var i = 0;i < array.length;++i) { | ||
var c = array[i].toString('16'); | ||
hex += c.length == 1 ? '0' + c : c; | ||
} | ||
return hex; | ||
}; | ||
describe('more than 64 bytes', function() { | ||
it('should be successful', function() { | ||
expect(md5('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('f63872ef7bc97a8a8eadba6f0881de53'); | ||
}); | ||
}); | ||
}); | ||
var testCases = { | ||
'ascii': { | ||
'd41d8cd98f00b204e9800998ecf8427e': '', | ||
'9e107d9d372bb6826bd81d3542a419d6': 'The quick brown fox jumps over the lazy dog', | ||
'e4d909c290d0fb1ca068ffaddf22cbd0': 'The quick brown fox jumps over the lazy dog.' | ||
}, | ||
'ascii more than 64 bytes': { | ||
'f63872ef7bc97a8a8eadba6f0881de53': 'The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.' | ||
}, | ||
'UTF8': { | ||
'a7bac2239fcdcb3a067903d8077c4a07': '中文', | ||
'ec3edbf3b05a449fc206a0138c739c3b': 'aécio', | ||
'b90869aaf121210f6c563973fa855650': '𠜎' | ||
}, | ||
'UTF8 more than 64 bytes': { | ||
'edce615b179e6e29be23145b77ebbd61': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一', | ||
'ad36c9ab669a0ba9ce46d3ce9134de34': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。' | ||
}, | ||
'special length': { | ||
'a119de63e4b2398427da06dd780263b3': '0123456780123456780123456780123456780123456780123456780', | ||
'ddafd84ebe63aebc4626b037a569d78b': '01234567801234567801234567801234567801234567801234567801', | ||
'9ea04d743618797ce464445b5785a630': '0123456780123456780123456780123456780123456780123456780123456780', | ||
'658d914ae42c4938874b2e786ccda479': '01234567801234567801234567801234567801234567801234567801234567801234567', | ||
'a083a3710d685793f1f17988bfe3c175': '012345678012345678012345678012345678012345678012345678012345678012345678', | ||
'2b21a843cfc31c8026a0d835bc91bc98': '012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678', | ||
'd02ebde979264c79e141559fc9f6b65c': '012345678901234567', | ||
'1ced811af47ead374872fcca9d73dd71': '012345678901234567890123456789012345678901234567890123456789', | ||
'ffb81a243a60dac45929300873e05287': '012345678901234567中文', | ||
}, | ||
'Array': { | ||
'd41d8cd98f00b204e9800998ecf8427e': [], | ||
'93b885adfe0da089cdf634904fd59f71': [0], | ||
'9e107d9d372bb6826bd81d3542a419d6': [84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103] | ||
}, | ||
'Uint8Array': { | ||
'9e107d9d372bb6826bd81d3542a419d6': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) | ||
}, | ||
'Int8Array': { | ||
'9e107d9d372bb6826bd81d3542a419d6': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) | ||
}, | ||
'ArrayBuffer': { | ||
'93b885adfe0da089cdf634904fd59f71': new ArrayBuffer(1) | ||
}, | ||
'Object': { | ||
'd41d8cd98f00b204e9800998ecf8427e': {}, | ||
'd41d8cd98f00b204e9800998ecf8427e': {what: 'ever'} | ||
} | ||
}; | ||
describe('UTF8', function() { | ||
describe('less than 64 bytes', function() { | ||
it('should be successful', function() { | ||
expect(md5('中文')).to.be('a7bac2239fcdcb3a067903d8077c4a07'); | ||
expect(md5('aécio')).to.be('ec3edbf3b05a449fc206a0138c739c3b'); | ||
expect(md5('𠜎')).to.be('b90869aaf121210f6c563973fa855650'); | ||
}); | ||
}); | ||
var methods = [ | ||
{ | ||
name: 'md5', | ||
call: md5, | ||
}, | ||
{ | ||
name: 'md5.hex', | ||
call: md5.hex | ||
}, | ||
{ | ||
name: 'md5.array', | ||
call: function (message) { | ||
return md5.array(message).toHexString(); | ||
} | ||
}, | ||
{ | ||
name: 'md5.digest', | ||
call: function (message) { | ||
return md5.digest(message).toHexString(); | ||
} | ||
}, | ||
{ | ||
name: 'md5.buffer', | ||
call: function (message) { | ||
return md5.buffer(message).toHexString(); | ||
} | ||
} | ||
]; | ||
describe('more than 64 bytes', function() { | ||
it('should be successful', function() { | ||
expect(md5('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('edce615b179e6e29be23145b77ebbd61'); | ||
expect(md5('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('ad36c9ab669a0ba9ce46d3ce9134de34'); | ||
}); | ||
}); | ||
}); | ||
var classMethods = [ | ||
{ | ||
name: 'create', | ||
call: function (message) { | ||
return md5.create().update(message).toString(); | ||
} | ||
}, | ||
{ | ||
name: 'update', | ||
call: function (message) { | ||
return md5.update(message).toString(); | ||
} | ||
}, | ||
{ | ||
name: 'hex', | ||
call: function (message) { | ||
return md5.update(message).hex(); | ||
} | ||
}, | ||
{ | ||
name: 'array', | ||
call: function (message) { | ||
return md5.update(message).array().toHexString(); | ||
} | ||
}, | ||
{ | ||
name: 'digest', | ||
call: function (message) { | ||
return md5.update(message).digest().toHexString(); | ||
} | ||
}, | ||
{ | ||
name: 'buffer', | ||
call: function (message) { | ||
return md5.update(message).buffer().toHexString(); | ||
} | ||
}, | ||
{ | ||
name: 'finalize', | ||
call: function (message) { | ||
var hash = md5.update(message); | ||
hash.hex(); | ||
hash.update(message); | ||
return hash.hex(); | ||
} | ||
} | ||
]; | ||
describe('special length', function() { | ||
it('should be successful', function() { | ||
expect(md5('0123456780123456780123456780123456780123456780123456780')).to.be('a119de63e4b2398427da06dd780263b3'); | ||
expect(md5('01234567801234567801234567801234567801234567801234567801')).to.be('ddafd84ebe63aebc4626b037a569d78b'); | ||
expect(md5('0123456780123456780123456780123456780123456780123456780123456780')).to.be('9ea04d743618797ce464445b5785a630'); | ||
expect(md5('01234567801234567801234567801234567801234567801234567801234567801234567')).to.be('658d914ae42c4938874b2e786ccda479'); | ||
expect(md5('012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('a083a3710d685793f1f17988bfe3c175'); | ||
expect(md5('012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('2b21a843cfc31c8026a0d835bc91bc98'); | ||
}); | ||
methods.forEach(function (method) { | ||
describe('#' + method.name, function () { | ||
for (var testCaseName in testCases) { | ||
(function (testCaseName) { | ||
var testCase = testCases[testCaseName]; | ||
context('when ' + testCaseName, function () { | ||
for (var hash in testCase) { | ||
(function (message, hash) { | ||
it('should be equal', function () { | ||
expect(method.call(message)).to.be(hash); | ||
}); | ||
})(testCase[hash], hash); | ||
} | ||
}); | ||
})(testCaseName); | ||
} | ||
}); | ||
}); | ||
describe('Array', function() { | ||
describe('Array', function() { | ||
it('should be successful', function() { | ||
expect(md5([])).to.be('d41d8cd98f00b204e9800998ecf8427e'); | ||
expect(md5([0])).to.be('93b885adfe0da089cdf634904fd59f71'); | ||
expect(md5([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103])).to.be('9e107d9d372bb6826bd81d3542a419d6'); | ||
describe('Md5', function () { | ||
classMethods.forEach(function (method) { | ||
describe('#' + method.name, function () { | ||
for (var testCaseName in testCases) { | ||
(function (testCaseName) { | ||
var testCase = testCases[testCaseName]; | ||
context('when ' + testCaseName, function () { | ||
for (var hash in testCase) { | ||
(function (message, hash) { | ||
it('should be equal', function () { | ||
expect(method.call(message)).to.be(hash); | ||
}); | ||
})(testCase[hash], hash); | ||
} | ||
}); | ||
})(testCaseName); | ||
} | ||
}); | ||
}); | ||
}); | ||
// describe('md5', function() { | ||
// describe('ascii', function() { | ||
// describe('less than 64 bytes', function() { | ||
// it('should be successful', function() { | ||
// expect(md5('')).to.be('d41d8cd98f00b204e9800998ecf8427e'); | ||
// expect(md5('The quick brown fox jumps over the lazy dog')).to.be('9e107d9d372bb6826bd81d3542a419d6'); | ||
// expect(md5('The quick brown fox jumps over the lazy dog.')).to.be('e4d909c290d0fb1ca068ffaddf22cbd0'); | ||
// }); | ||
// }); | ||
describe('Uint8Array', function() { | ||
it('should be successful', function() { | ||
expect(md5(new Uint8Array([]))).to.be('d41d8cd98f00b204e9800998ecf8427e'); | ||
expect(md5(new Uint8Array(371))).to.be('58f494c2a0fb65332110fb62ae5c4a74'); | ||
}); | ||
}); | ||
// describe('more than 64 bytes', function() { | ||
// it('should be successful', function() { | ||
// expect(md5('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('f63872ef7bc97a8a8eadba6f0881de53'); | ||
// }); | ||
// }); | ||
// }); | ||
describe('ArrayBuffer', function() { | ||
it('should be successful', function() { | ||
expect(md5(new ArrayBuffer(0))).to.be('d41d8cd98f00b204e9800998ecf8427e'); | ||
expect(md5(new ArrayBuffer(1))).to.be('93b885adfe0da089cdf634904fd59f71'); | ||
}); | ||
}); | ||
}); | ||
// describe('UTF8', function() { | ||
// describe('less than 64 bytes', function() { | ||
// it('should be successful', function() { | ||
// expect(md5('中文')).to.be('a7bac2239fcdcb3a067903d8077c4a07'); | ||
// expect(md5('aécio')).to.be('ec3edbf3b05a449fc206a0138c739c3b'); | ||
// expect(md5('𠜎')).to.be('b90869aaf121210f6c563973fa855650'); | ||
// }); | ||
// }); | ||
// describe('more than 64 bytes', function() { | ||
// it('should be successful', function() { | ||
// expect(md5('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('edce615b179e6e29be23145b77ebbd61'); | ||
// expect(md5('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('ad36c9ab669a0ba9ce46d3ce9134de34'); | ||
// }); | ||
// }); | ||
// }); | ||
// describe('special length', function() { | ||
// it('should be successful', function() { | ||
// expect(md5('0123456780123456780123456780123456780123456780123456780')).to.be('a119de63e4b2398427da06dd780263b3'); | ||
// expect(md5('01234567801234567801234567801234567801234567801234567801')).to.be('ddafd84ebe63aebc4626b037a569d78b'); | ||
// expect(md5('0123456780123456780123456780123456780123456780123456780123456780')).to.be('9ea04d743618797ce464445b5785a630'); | ||
// expect(md5('01234567801234567801234567801234567801234567801234567801234567801234567')).to.be('658d914ae42c4938874b2e786ccda479'); | ||
// expect(md5('012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('a083a3710d685793f1f17988bfe3c175'); | ||
// expect(md5('012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('2b21a843cfc31c8026a0d835bc91bc98'); | ||
// }); | ||
// }); | ||
// }); | ||
// describe('Array', function() { | ||
// describe('Array', function() { | ||
// it('should be successful', function() { | ||
// expect(md5([])).to.be('d41d8cd98f00b204e9800998ecf8427e'); | ||
// expect(md5([0])).to.be('93b885adfe0da089cdf634904fd59f71'); | ||
// expect(md5([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103])).to.be('9e107d9d372bb6826bd81d3542a419d6'); | ||
// }); | ||
// }); | ||
// describe('Uint8Array', function() { | ||
// it('should be successful', function() { | ||
// expect(md5(new Uint8Array([]))).to.be('d41d8cd98f00b204e9800998ecf8427e'); | ||
// expect(md5(new Uint8Array(371))).to.be('58f494c2a0fb65332110fb62ae5c4a74'); | ||
// }); | ||
// }); | ||
// describe('ArrayBuffer', function() { | ||
// it('should be successful', function() { | ||
// expect(md5(new ArrayBuffer(0))).to.be('d41d8cd98f00b204e9800998ecf8427e'); | ||
// expect(md5(new ArrayBuffer(1))).to.be('93b885adfe0da089cdf634904fd59f71'); | ||
// }); | ||
// }); | ||
// }); | ||
})(md5); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
1134191
44
1447
6
1
75
13