diff --git a/js/md5.js b/js/md5.js index f92ba37..79bbd5a 100644 --- a/js/md5.js +++ b/js/md5.js @@ -7,7 +7,7 @@ * * Licensed under the MIT license: * http://www.opensource.org/licenses/MIT - * + * * Based on * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. @@ -251,23 +251,33 @@ return rstr2hex(raw_hmac_md5(k, d)); } - function md5(string, key, raw) { + function md5(data, key, raw) { + if (typeof data === 'object') { + data = JSON.stringify(data); + } + + if (typeof data === 'function') { + data = data.toString(); + } + if (!key) { if (!raw) { - return hex_md5(string); + return hex_md5(data); } - return raw_md5(string); + return raw_md5(data); } if (!raw) { - return hex_hmac_md5(key, string); + return hex_hmac_md5(key, data); } - return raw_hmac_md5(key, string); + return raw_hmac_md5(key, data); } if (typeof define === 'function' && define.amd) { define(function () { return md5; }); + } else if (typeof module === 'object' && module.exports) { + module.exports = md5; } else { $.md5 = md5; } diff --git a/js/md5.min.js b/js/md5.min.js index a571fa1..04e1644 100644 --- a/js/md5.min.js +++ b/js/md5.min.js @@ -1 +1 @@ -!function(n){"use strict";function t(n,t){var r=(65535&n)+(65535&t),e=(n>>16)+(t>>16)+(r>>16);return e<<16|65535&r}function r(n,t){return n<>>32-t}function e(n,e,u,o,c,f){return t(r(t(t(e,n),t(o,f)),c),u)}function u(n,t,r,u,o,c,f){return e(t&r|~t&u,n,t,o,c,f)}function o(n,t,r,u,o,c,f){return e(t&u|r&~u,n,t,o,c,f)}function c(n,t,r,u,o,c,f){return e(t^r^u,n,t,o,c,f)}function f(n,t,r,u,o,c,f){return e(r^(t|~u),n,t,o,c,f)}function i(n,r){n[r>>5]|=128<>>9<<4)+14]=r;var e,i,a,h,d,g=1732584193,l=-271733879,v=-1732584194,C=271733878;for(e=0;e>5]>>>t%32);return r}function h(n){var t,r=[];for(r[(n.length>>2)-1]=void 0,t=0;t>5]|=(255&n.charCodeAt(t/8))<16&&(u=i(u,8*n.length)),r=0;16>r;r+=1)o[r]=909522486^u[r],c[r]=1549556828^u[r];return e=i(o.concat(h(t)),512+8*t.length),a(i(c.concat(e),640))}function l(n){var t,r,e="0123456789abcdef",u="";for(r=0;r>>4)+e.charAt(15&t);return u}function v(n){return unescape(encodeURIComponent(n))}function C(n){return d(v(n))}function m(n){return l(C(n))}function s(n,t){return g(v(n),v(t))}function A(n,t){return l(s(n,t))}function p(n,t,r){return t?r?s(t,n):A(t,n):r?C(n):m(n)}"function"==typeof define&&define.amd?define(function(){return p}):n.md5=p}(this); \ No newline at end of file +!function(a){"use strict";function b(a,b){var c=(65535&a)+(65535&b),d=(a>>16)+(b>>16)+(c>>16);return d<<16|65535&c}function c(a,b){return a<>>32-b}function d(a,d,e,f,g,h){return b(c(b(b(d,a),b(f,h)),g),e)}function e(a,b,c,e,f,g,h){return d(b&c|~b&e,a,b,f,g,h)}function f(a,b,c,e,f,g,h){return d(b&e|c&~e,a,b,f,g,h)}function g(a,b,c,e,f,g,h){return d(b^c^e,a,b,f,g,h)}function h(a,b,c,e,f,g,h){return d(c^(b|~e),a,b,f,g,h)}function i(a,c){a[c>>5]|=128<>>9<<4)+14]=c;var d,i,j,k,l,m=1732584193,n=-271733879,o=-1732584194,p=271733878;for(d=0;d>5]>>>b%32);return c}function k(a){var b,c=[];for(c[(a.length>>2)-1]=void 0,b=0;b>5]|=(255&a.charCodeAt(b/8))<16&&(d=i(d,8*a.length)),c=0;16>c;c+=1)e[c]=909522486^d[c],f[c]=1549556828^d[c];return g=i(e.concat(k(b)),512+8*b.length),j(i(f.concat(g),640))}function n(a){var d,e,b="0123456789abcdef",c="";for(e=0;e>>4)+b.charAt(15&d);return c}function o(a){return unescape(encodeURIComponent(a))}function p(a){return l(o(a))}function q(a){return n(p(a))}function r(a,b){return m(o(a),o(b))}function s(a,b){return n(r(a,b))}function t(a,b,c){return"object"==typeof a&&(a=JSON.stringify(a)),"function"==typeof a&&(a=a.toString()),b?c?r(b,a):s(b,a):c?p(a):q(a)}"function"==typeof define&&define.amd?define(function(){return t}):"object"==typeof module&&module.exports?module.exports=t:a.md5=t}(this);