声明:
本文章中所有内容仅供学习交流使用,不用于其他任何目的,抓包内容、敏感网址、数据接口等均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关!
有相关问题请第一时间头像私信联系我删除博客!
前言
简单分析一下京东的h5st加密流程。
h5st
现需要对body进行sha256加密。
sha256_digest: function(t) {
function e(t, e) {
var r = (65535 & t) + (65535 & e);
return (t >> 16) + (e >> 16) + (r >> 16) << 16 | 65535 & r
}
function r(t, e) {
return t >>> e | t << 32 - e
}
function n(t, e) {
return t >>> e
}
function o(t, e, r) {
return t & e ^ ~t & r
}
function i(t, e, r) {
return t & e ^ t & r ^ e & r
}
function a(t) {
return r(t, 2) ^ r(t, 13) ^ r(t, 22)
}
function s(t) {
return r(t, 6) ^ r(t, 11) ^ r(t, 25)
}
function u(t) {
return r(t, 7) ^ r(t, 18) ^ n(t, 3)
}
return function(t) {
for (var e = "0123456789abcdef", r = "", n = 0; n < 4 * t.length; n++)
r += e.charAt(t[n >> 2] >> 8 * (3 - n % 4) + 4 & 15) + e.charAt(t[n >> 2] >> 8 * (3 - n % 4) & 15);
return r
}(function(t, c) {
var l, d, f, p, v, h, m, g, y, w, b, _ = new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298), x = new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225), j = new Array(64);
t[c >> 5] |= 128 << 24 - c % 32,
t[15 + (c + 64 >> 9 << 4)] = c;
for (var A = 0; A < t.length; A += 16) {
l = x[0],
d = x[1],
f = x[2],
p = x[3],
v = x[4],
h = x[5],
m = x[6],
g = x[7];
for (var k = 0; k < 64; k++)
j[k] = k < 16 ? t[k + A] : e(e(e(r(b = j[k - 2], 17) ^ r(b, 19) ^ n(b, 10), j[k - 7]), u(j[k - 15])), j[k - 16]),
y = e(e(e(e(g, s(v)), o(v, h, m)), _[k]), j[k]),
w = e(a(l), i(l, d, f)),
g = m,
m = h,
h = v,
v = e(p, y),
p = f,
f = d,
d = l,
l = e(y, w);
x[0] = e(l, x[0]),
x[1] = e(d, x[1]),
x[2] = e(f, x[2]),
x[3] = e(p, x[3]),
x[4] = e(v, x[4]),
x[5] = e(h, x[5]),
x[6] = e(m, x[6]),
x[7] = e(g, x[7])
}
return x
}(function(t) {
for (var e = Array(), r = 0; r < 8 * t.length; r += 8)
e[r >> 5] |= (255 & t.charCodeAt(r / 8)) << 24 - r % 32;
return e
}(t = function(t) {
t = t.replace(/\r\n/g, "\n");
for (var e = "", r = 0; r < t.length; r++) {
var n = t.charCodeAt(r);
n < 128 ? e += String.fromCharCode(n) : n > 127 && n < 2048 ? (e += String.fromCharCode(n >> 6 | 192),
e += String.fromCharCode(63 & n | 128)) : (e += String.fromCharCode(n >> 12 | 224),
e += String.fromCharCode(n >> 6 & 63 | 128),
e += String.fromCharCode(63 & n | 128))
}
return e
}(t)), 8 * t.length))
}
接着通过sign方法初始化最后加密。