Skip to content

Commit

Permalink
v0.5.27 fix md5.js 报毒
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Jun 30, 2020
1 parent 7b12193 commit 9988c08
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 245 deletions.
143 changes: 37 additions & 106 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2101,14 +2101,19 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '0.5.26';
COS.version = '0.5.27';

module.exports = COS;

/***/ }),
/* 6 */
/***/ (function(module, exports) {

/**
* http://www.myersdaily.org/joseph/javascript/md5-text.html
* http://pajhome.org.uk/crypt/md5
* https://github.com/wbond/md5-js
*/
function md5cycle(x, k) {
var a = x[0],
b = x[1],
Expand Down Expand Up @@ -2210,44 +2215,41 @@ function ii(a, b, c, d, x, s, t) {
return cmn(c ^ (b | ~d), a, b, x, s, t);
}

function md51(s) {
var n = s.length,
state = [1732584193, -271733879, -1732584194, 271733878],
i;
for (i = 64; i <= s.length; i += 64) {
md5cycle(state, md5blk(s.substring(i - 64, i)));
}
s = s.substring(i - 64);
var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (i = 0; i < s.length; i++) tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3);
tail[i >> 2] |= 0x80 << (i % 4 << 3);
if (i > 55) {
md5cycle(state, tail);
for (i = 0; i < 16; i++) tail[i] = 0;
function md5blk(s) {
/* I figured global was faster. */
var md5blks = [],
i; /* Andy King said do it this way. */
for (i = 0; i < 64; i += 4) {
md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);
}
tail[14] = n * 8;
md5cycle(state, tail);
return state;
return md5blks;
}

var binaryBase64 = function (str) {
var i,
len,
char,
res = '';
for (i = 0, len = str.length / 2; i < len; i++) {
char = parseInt(str[i * 2] + str[i * 2 + 1], 16);
res += String.fromCharCode(char);
}
return btoa(res);
var hex_chr = '0123456789abcdef'.split('');

function rhex(n) {
var s = '',
j = 0;
for (; j < 4; j++) s += hex_chr[n >> j * 8 + 4 & 0x0F] + hex_chr[n >> j * 8 & 0x0F];
return s;
}

function hex(x) {
for (var i = 0; i < x.length; i++) x[i] = rhex(x[i]);
return x.join('');
}

var add32 = function (a, b) {
return a + b & 0xFFFFFFFF;
};

function getCtx() {
var ctx = {};
ctx.state = [1732584193, -271733879, -1732584194, 271733878];
ctx.tail = '';
ctx.size = 0;
ctx.update = function (s, isBinaryString) {
if (!isBinaryString) s = Utf8Encode(s);
ctx.update = function (s, isBinStr) {
if (!isBinStr) s = unescape(encodeURIComponent(s));
ctx.size += s.length;
s = ctx.tail + s;
var i,
Expand All @@ -2272,86 +2274,16 @@ function getCtx() {
}
tail[14] = n * 8;
md5cycle(state, tail);
return encode === 'hex' ? hex(state) : encode === 'base64' ? binaryBase64(hex(state)) : state;
return hex(state);
};
return ctx;
}

/* there needs to be support for Unicode here,
* unless we pretend that we can redefine the MD-5
* algorithm for multi-byte characters (perhaps
* by adding every four 16-bit characters and
* shortening the sum to 32 bits). Otherwise
* I suggest performing MD-5 as if every character
* was two bytes--e.g., 0040 0025 = @%--but then
* how will an ordinary MD-5 sum be matched?
* There is no way to standardize text to something
* like UTF-8 before transformation; speed cost is
* utterly prohibitive. The JavaScript standard
* itself needs to look at this: it should start
* providing access to strings as preformed UTF-8
* 8-bit unsigned value arrays.
*/
function md5blk(s) {
/* I figured global was faster. */
var md5blks = [],
i; /* Andy King said do it this way. */
for (i = 0; i < 64; i += 4) {
md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);
}
return md5blks;
}

var hex_chr = '0123456789abcdef'.split('');

function rhex(n) {
var s = '',
j = 0;
for (; j < 4; j++) s += hex_chr[n >> j * 8 + 4 & 0x0F] + hex_chr[n >> j * 8 & 0x0F];
return s;
}

function hex(x) {
for (var i = 0; i < x.length; i++) x[i] = rhex(x[i]);
return x.join('');
}

function Utf8Encode(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if (c > 127 && c < 2048) {
utftext += String.fromCharCode(c >> 6 | 192);
utftext += String.fromCharCode(c & 63 | 128);
} else {
utftext += String.fromCharCode(c >> 12 | 224);
utftext += String.fromCharCode(c >> 6 & 63 | 128);
utftext += String.fromCharCode(c & 63 | 128);
}
}
return utftext;
}

function md5(s, isBinaryString) {
if (!isBinaryString) {
s = Utf8Encode(s);
}
return hex(md51(s));
}

/* this function is much faster,
so if possible we use it. Some IEs
are the only ones I know of that
need the idiotic second function,
generated by an if clause. */

var add32 = function (a, b) {
return a + b & 0xFFFFFFFF;
var md5 = function (s, isBinStr) {
return getCtx().update(s, isBinStr).digest('hex');
};
if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') {

if (md5('hello') !== '5d41402abc4b2a76b9719d911017c592') {
add32 = function (x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF),
msw = (x >> 16) + (y >> 16) + (lsw >> 16);
Expand All @@ -2360,7 +2292,6 @@ if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') {
}

md5.getCtx = getCtx;

module.exports = md5;

/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 9988c08

Please sign in to comment.