jsencrypt参数前端加密c#解密

2021-02-10 12:17

阅读:418

      写程序时一般是通过form表单或者ajax方式将参数提交到服务器进行验证,如何防止提交的请求不被抓包后串改,虽然无法说绝对安全却给非法提交提高了难度,本篇采用jsencypt在前端进行加密的并且用C#在后端解密,在投票提交分数等H5应用上可以使用的上,并且进行简单的封装。

1.demo

技术分享图片

DOCTYPE html>
html xmlns="http://www.w3.org/1999/xhtml">
head>
    meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    title>title>
    script src="/Scripts/jquery-1.10.2.min.js">script>
    script src="/Scripts/JsEncryptHelper.js">script>
head>
body>

body>
html>

body>
    form id="form1>
        

 

输入账号密码后加密后到服务端解密后返回

 

2.客户端

写一个JsEncryptHelper.js  以后需要加密的页面都可以应用

var JSEncryptExports = {};
(function (exports) {
    function BigInteger(a, b, c) { null != a && ("number" == typeof a ? this.fromNumber(a, b, c) : null == b && "string" != typeof a ? this.fromString(a, 256) : this.fromString(a, b)) } function nbi() { return new BigInteger(null) } function am1(a, b, c, d, e, f) { for (; --f >= 0;) { var g = b * this[a++] + c[d] + e; e = Math.floor(g / 67108864), c[d++] = 67108863 & g } return e } function am2(a, b, c, d, e, f) { for (var g = 32767 & b, h = b >> 15; --f >= 0;) { var i = 32767 & this[a], j = this[a++] >> 15, k = h * i + j * g; i = g * i + ((32767 & k) >> 30) + (k >>> 15) + h * j + (e >>> 30), c[d++] = 1073741823 & i } return e } function am3(a, b, c, d, e, f) { for (var g = 16383 & b, h = b >> 14; --f >= 0;) { var i = 16383 & this[a], j = this[a++] >> 14, k = h * i + j * g; i = g * i + ((16383 & k) > 28) + (k >> 14) + h * j, c[d++] = 268435455 & i } return e } function int2char(a) { return BI_RM.charAt(a) } function intAt(a, b) { var c = BI_RC[a.charCodeAt(b)]; return null == c ? -1 : c } function bnpCopyTo(a) { for (var b = this.t - 1; b >= 0; --b) a[b] = this[b]; a.t = this.t, a.s = this.s } function bnpFromInt(a) { this.t = 1, this.s = 0 > a ? -1 : 0, a > 0 ? this[0] = a : -1 > a ? this[0] = a + DV : this.t = 0 } function nbv(a) { var b = nbi(); return b.fromInt(a), b } function bnpFromString(a, b) { var c; if (16 == b) c = 4; else if (8 == b) c = 3; else if (256 == b) c = 8; else if (2 == b) c = 1; else if (32 == b) c = 5; else { if (4 != b) return void this.fromRadix(a, b); c = 2 } this.t = 0, this.s = 0; for (var d = a.length, e = !1, f = 0; --d >= 0;) { var g = 8 == c ? 255 & a[d] : intAt(a, d); 0 > g ? "-" == a.charAt(d) && (e = !0) : (e = !1, 0 == f ? this[this.t++] = g : f + c > this.DB ? (this[this.t - 1] |= (g & (1 this.DB - f) - 1) this[this.t++] = g >> this.DB - f) : this[this.t - 1] |= g = this.DB && (f -= this.DB)) } 8 == c && 0 != (128 & a[0]) && (this.s = -1, f > 0 && (this[this.t - 1] |= (1 this.DB - f) - 1 this.clamp(), e && BigInteger.ZERO.subTo(this, this) } function bnpClamp() { for (var a = this.s & this.DM; this.t > 0 && this[this.t - 1] == a;)--this.t } function bnToString(a) { if (this.s return "-" + this.negate().toString(a); var b; if (16 == a) b = 4; else if (8 == a) b = 3; else if (2 == a) b = 1; else if (32 == a) b = 5; else { if (4 != a) return this.toRadix(a); b = 2 } var c, d = (1 this.t, h = this.DB - g * this.DB % b; if (g-- > 0) for (h this.DB && (c = this[g] >> h) > 0 && (e = !0, f = int2char(c)) ; g >= 0;) b > h ? (c = (this[g] & (1 this[--g] >> (h += this.DB - b)) : (c = this[g] >> (h -= b) & d, 0 >= h && (h += this.DB, --g)), c > 0 && (e = !0), e && (f += int2char(c)); return e ? f : "0" } function bnNegate() { var a = nbi(); return BigInteger.ZERO.subTo(this, a), a } function bnAbs() { return this.s this.negate() : this } function bnCompareTo(a) { var b = this.s - a.s; if (0 != b) return b; var c = this.t; if (b = c - a.t, 0 != b) return this.s for (; --c >= 0;) if (0 != (b = this[c] - a[c])) return b; return 0 } function nbits(a) { var b, c = 1; return 0 != (b = a >>> 16) && (a = b, c += 16), 0 != (b = a >> 8) && (a = b, c += 8), 0 != (b = a >> 4) && (a = b, c += 4), 0 != (b = a >> 2) && (a = b, c += 2), 0 != (b = a >> 1) && (a = b, c += 1), c } function bnBitLength() { return this.t this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ this.s & this.DM) } function bnpDLShiftTo(a, b) { var c; for (c = this.t - 1; c >= 0; --c) b[c + a] = this[c]; for (c = a - 1; c >= 0; --c) b[c] = 0; b.t = this.t + a, b.s = this.s } function bnpDRShiftTo(a, b) { for (var c = a; c this.t; ++c) b[c - a] = this[c]; b.t = Math.max(this.t - a, 0), b.s = this.s } function bnpLShiftTo(a, b) { var c, d = a % this.DB, e = this.DB - d, f = (1 this.DB), h = this.s this.DM; for (c = this.t - 1; c >= 0; --c) b[c + g + 1] = this[c] >> e | h, h = (this[c] & f) for (c = g - 1; c >= 0; --c) b[c] = 0; b[g] = h, b.t = this.t + g + 1, b.s = this.s, b.clamp() } function bnpRShiftTo(a, b) { b.s = this.s; var c = Math.floor(a / this.DB); if (c >= this.t) return void (b.t = 0); var d = a % this.DB, e = this.DB - d, f = (1 this[c] >> d; for (var g = c + 1; g this.t; ++g) b[g - c - 1] |= (this[g] & f) this[g] >> d; d > 0 && (b[this.t - c - 1] |= (this.s & f) this.t - c, b.clamp() } function bnpSubTo(a, b) { for (var c = 0, d = 0, e = Math.min(a.t, this.t) ; e > c;) d += this[c] - a[c], b[c++] = d & this.DM, d >>= this.DB; if (a.t this.t) { for (d -= a.s; c this.t;) d += this[c], b[c++] = d & this.DM, d >>= this.DB; d += this.s } else { for (d += this.s; c this.DM, d >>= this.DB; d -= a.s } b.s = 0 > d ? -1 : 0, -1 > d ? b[c++] = this.DV + d : d > 0 && (b[c++] = d), b.t = c, b.clamp() } function bnpMultiplyTo(a, b) { var c = this.abs(), d = a.abs(), e = c.t; for (b.t = e + d.t; --e >= 0;) b[e] = 0; for (e = 0; e this.s != a.s && BigInteger.ZERO.subTo(b, b) } function bnpSquareTo(a) { for (var b = this.abs(), c = a.t = 2 * b.t; --c >= 0;) a[c] = 0; for (c = 0; c var d = b.am(c, b[c], a, 2 * c, 0, 1); (a[c + b.t] += b.am(c + 1, 2 * b[c], a, 2 * c + 1, d, b.t - c - 1)) >= b.DV && (a[c + b.t] -= b.DV, a[c + b.t + 1] = 1) } a.t > 0 && (a[a.t - 1] += b.am(c, b[c], a, 2 * c, 0, 1)), a.s = 0, a.clamp() } function bnpDivRemTo(a, b, c) { var d = a.abs(); if (!(d.t var e = this.abs(); if (e.t return null != b && b.fromInt(0), void (null != c && this.copyTo(c)); null == c && (c = nbi()); var f = nbi(), g = this.s, h = a.s, i = this.DB - nbits(d[d.t - 1]); i > 0 ? (d.lShiftTo(i, f), e.lShiftTo(i, c)) : (d.copyTo(f), e.copyTo(c)); var j = f.t, k = f[j - 1]; if (0 != k) { var l = k * (1 this.F1) + (j > 1 ? f[j - 2] >> this.F2 : 0), m = this.FV / l, n = (1 this.F1) / l, o = 1 this.F2, p = c.t, q = p - j, r = null == b ? nbi() : b; for (f.dlShiftTo(q, r), c.compareTo(r) >= 0 && (c[c.t++] = 1, c.subTo(r, c)), BigInteger.ONE.dlShiftTo(j, r), r.subTo(f, f) ; f.t for (; --q >= 0;) { var s = c[--p] == k ? this.DM : Math.floor(c[p] * m + (c[p - 1] + o) * n); if ((c[p] += f.am(0, s, c, q, 0, j)) for (f.dlShiftTo(q, r), c.subTo(r, c) ; c[p] null != b && (c.drShiftTo(j, b), g != h && BigInteger.ZERO.subTo(b, b)), c.t = j, c.clamp(), i > 0 && c.rShiftTo(i, c), 0 > g && BigInteger.ZERO.subTo(c, c) } } } function bnMod(a) { var b = nbi(); return this.abs().divRemTo(a, null, b), this.s  0 && a.subTo(b, b), b } function Classic(a) { this.m = a } function cConvert(a) { return a.s this.m) >= 0 ? a.mod(this.m) : a } function cRevert(a) { return a } function cReduce(a) { a.divRemTo(this.m, null, a) } function cMulTo(a, b, c) { a.multiplyTo(b, c), this.reduce(c) } function cSqrTo(a, b) { a.squareTo(b), this.reduce(b) } function bnpInvDigit() { if (this.t return 0; var a = this[0]; if (0 == (1 & a)) return 0; var b = 3 & a; return b = b * (2 - (15 & a) * b) & 15, b = b * (2 - (255 & a) * b) & 255, b = b * (2 - ((65535 & a) * b & 65535)) & 65535, b = b * (2 - a * b % this.DV) % this.DV, b > 0 ? this.DV - b : -b } function Montgomery(a) { this.m = a, this.mp = a.invDigit(), this.mpl = 32767 & this.mp, this.mph = this.mp >> 15, this.um = (1 this.mt2 = 2 * a.t } function montConvert(a) { var b = nbi(); return a.abs().dlShiftTo(this.m.t, b), b.divRemTo(this.m, null, b), a.s  0 && this.m.subTo(b, b), b } function montRevert(a) { var b = nbi(); return a.copyTo(b), this.reduce(b), b } function montReduce(a) { for (; a.t this.mt2;) a[a.t++] = 0; for (var b = 0; b this.m.t; ++b) { var c = 32767 & a[b], d = c * this.mpl + ((c * this.mph + (a[b] >> 15) * this.mpl & this.um) for (c = b + this.m.t, a[c] += this.m.am(0, d, a, b, 0, this.m.t) ; a[c] >= a.DV;) a[c] -= a.DV, a[++c]++ } a.clamp(), a.drShiftTo(this.m.t, a), a.compareTo(this.m) >= 0 && a.subTo(this.m, a) } function montSqrTo(a, b) { a.squareTo(b), this.reduce(b) } function montMulTo(a, b, c) { a.multiplyTo(b, c), this.reduce(c) } function bnpIsEven() { return 0 == (this.t > 0 ? 1 & this[0] : this.s) } function bnpExp(a, b) { if (a > 4294967295 || 1 > a) return BigInteger.ONE; var c = nbi(), d = nbi(), e = b.convert(this), f = nbits(a) - 1; for (e.copyTo(c) ; --f >= 0;) if (b.sqrTo(c, d), (a & 1  0) b.mulTo(d, e, c); else { var g = c; c = d, d = g } return b.revert(c) } function bnModPowInt(a, b) { var c; return c = 256 > a || b.isEven() ? new Classic(b) : new Montgomery(b), this.exp(a, c) } function bnClone() { var a = nbi(); return this.copyTo(a), a } function bnIntValue() { if (this.s if (1 == this.t) return this[0] - this.DV; if (0 == this.t) return -1 } else { if (1 == this.t) return this[0]; if (0 == this.t) return 0 } return (this[1] & (1 this.DB) - 1) this.DB | this[0] } function bnByteValue() { return 0 == this.t ? this.s : this[0] > 24 } function bnShortValue() { return 0 == this.t ? this.s : this[0] > 16 } function bnpChunkSize(a) { return Math.floor(Math.LN2 * this.DB / Math.log(a)) } function bnSigNum() { return this.s this.t this.t && this[0] function bnpToRadix(a) { if (null == a && (a = 10), 0 == this.signum() || 2 > a || a > 36) return "0"; var b = this.chunkSize(a), c = Math.pow(a, b), d = nbv(c), e = nbi(), f = nbi(), g = ""; for (this.divRemTo(d, e, f) ; e.signum() > 0;) g = (c + f.intValue()).toString(a).substr(1) + g, e.divRemTo(d, e, f); return f.intValue().toString(a) + g } function bnpFromRadix(a, b) { this.fromInt(0), null == b && (b = 10); for (var c = this.chunkSize(b), d = Math.pow(b, c), e = !1, f = 0, g = 0, h = 0; h var i = intAt(a, h); 0 > i ? "-" == a.charAt(h) && 0 == this.signum() && (e = !0) : (g = b * g + i, ++f >= c && (this.dMultiply(d), this.dAddOffset(g, 0), f = 0, g = 0)) } f > 0 && (this.dMultiply(Math.pow(b, f)), this.dAddOffset(g, 0)), e && BigInteger.ZERO.subTo(this, this) } function bnpFromNumber(a, b, c) { if ("number" == typeof b) if (2 > a) this.fromInt(1); else for (this.fromNumber(a, c), this.testBit(a - 1) || this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this), this.isEven() && this.dAddOffset(1, 0) ; !this.isProbablePrime(b) ;) this.dAddOffset(2, 0), this.bitLength() > a && this.subTo(BigInteger.ONE.shiftLeft(a - 1), this); else { var d = new Array, e = 7 & a; d.length = (a >> 3) + 1, b.nextBytes(d), e > 0 ? d[0] &= (1 this.fromString(d, 256) } } function bnToByteArray() { var a = this.t, b = new Array; b[0] = this.s; var c, d = this.DB - a * this.DB % 8, e = 0; if (a-- > 0) for (d this.DB && (c = this[a] >> d) != (this.s & this.DM) >> d && (b[e++] = c | this.s this.DB - d) ; a >= 0;) 8 > d ? (c = (this[a] & (1 this[--a] >> (d += this.DB - 8)) : (c = this[a] >> (d -= 8) & 255, 0 >= d && (d += this.DB, --a)), 0 != (128 & c) && (c |= -256), 0 == e && (128 & this.s) != (128 & c) && ++e, (e > 0 || c != this.s) && (b[e++] = c); return b } function bnEquals(a) { return 0 == this.compareTo(a) } function bnMin(a) { return this.compareTo(a) this : a } function bnMax(a) { return this.compareTo(a) > 0 ? this : a } function bnpBitwiseTo(a, b, c) { var d, e, f = Math.min(a.t, this.t); for (d = 0; f > d; ++d) c[d] = b(this[d], a[d]); if (a.t this.t) { for (e = a.s & this.DM, d = f; d this.t; ++d) c[d] = b(this[d], e); c.t = this.t } else { for (e = this.s & this.DM, d = f; d this.s, a.s), c.clamp() } function op_and(a, b) { return a & b } function bnAnd(a) { var b = nbi(); return this.bitwiseTo(a, op_and, b), b } function op_or(a, b) { return a | b } function bnOr(a) { var b = nbi(); return this.bitwiseTo(a, op_or, b), b } function op_xor(a, b) { return a ^ b } function bnXor(a) { var b = nbi(); return this.bitwiseTo(a, op_xor, b), b } function op_andnot(a, b) { return a & ~b } function bnAndNot(a) { var b = nbi(); return this.bitwiseTo(a, op_andnot, b), b } function bnNot() { for (var a = nbi(), b = 0; b this.t; ++b) a[b] = this.DM & ~this[b]; return a.t = this.t, a.s = ~this.s, a } function bnShiftLeft(a) { var b = nbi(); return 0 > a ? this.rShiftTo(-a, b) : this.lShiftTo(a, b), b } function bnShiftRight(a) { var b = nbi(); return 0 > a ? this.lShiftTo(-a, b) : this.rShiftTo(a, b), b } function lbit(a) { if (0 == a) return -1; var b = 0; return 0 == (65535 & a) && (a >>= 16, b += 16), 0 == (255 & a) && (a >>= 8, b += 8), 0 == (15 & a) && (a >>= 4, b += 4), 0 == (3 & a) && (a >>= 2, b += 2), 0 == (1 & a) && ++b, b } function bnGetLowestSetBit() { for (var a = 0; a this.t; ++a) if (0 != this[a]) return a * this.DB + lbit(this[a]); return this.s this.t * this.DB : -1 } function cbit(a) { for (var b = 0; 0 != a;) a &= a - 1, ++b; return b } function bnBitCount() { for (var a = 0, b = this.s & this.DM, c = 0; c this.t; ++c) a += cbit(this[c] ^ b); return a } function bnTestBit(a) { var b = Math.floor(a / this.DB); return b >= this.t ? 0 != this.s : 0 != (this[b] & 1 this.DB) } function bnpChangeBit(a, b) { var c = BigInteger.ONE.shiftLeft(a); return this.bitwiseTo(c, b, c), c } function bnSetBit(a) { return this.changeBit(a, op_or) } function bnClearBit(a) { return this.changeBit(a, op_andnot) } function bnFlipBit(a) { return this.changeBit(a, op_xor) } function bnpAddTo(a, b) { for (var c = 0, d = 0, e = Math.min(a.t, this.t) ; e > c;) d += this[c] + a[c], b[c++] = d & this.DM, d >>= this.DB; if (a.t this.t) { for (d += a.s; c this.t;) d += this[c], b[c++] = d & this.DM, d >>= this.DB; d += this.s } else { for (d += this.s; c this.DM, d >>= this.DB; d += a.s } b.s = 0 > d ? -1 : 0, d > 0 ? b[c++] = d : -1 > d && (b[c++] = this.DV + d), b.t = c, b.clamp() } function bnAdd(a) { var b = nbi(); return this.addTo(a, b), b } function bnSubtract(a) { var b = nbi(); return this.subTo(a, b), b } function bnMultiply(a) { var b = nbi(); return this.multiplyTo(a, b), b } function bnSquare() { var a = nbi(); return this.squareTo(a), a } function bnDivide(a) { var b = nbi(); return this.divRemTo(a, b, null), b } function bnRemainder(a) { var b = nbi(); return this.divRemTo(a, null, b), b } function bnDivideAndRemainder(a) { var b = nbi(), c = nbi(); return this.divRemTo(a, b, c), new Array(b, c) } function bnpDMultiply(a) { this[this.t] = this.am(0, a - 1, this, 0, 0, this.t), ++this.t, this.clamp() } function bnpDAddOffset(a, b) { if (0 != a) { for (; this.t this[this.t++] = 0; for (this[b] += a; this[b] >= this.DV;) this[b] -= this.DV, ++b >= this.t && (this[this.t++] = 0), ++this[b] } } function NullExp() { } function nNop(a) { return a } function nMulTo(a, b, c) { a.multiplyTo(b, c) } function nSqrTo(a, b) { a.squareTo(b) } function bnPow(a) { return this.exp(a, new NullExp) } function bnpMultiplyLowerTo(a, b, c) { var d = Math.min(this.t + a.t, b); for (c.s = 0, c.t = d; d > 0;) c[--d] = 0; var e; for (e = c.t - this.t; e > d; ++d) c[d + this.t] = this.am(0, a[d], c, d, 0, this.t); for (e = Math.min(a.t, b) ; e > d; ++d) this.am(0, a[d], c, d, 0, b - d); c.clamp() } function bnpMultiplyUpperTo(a, b, c) { --b; var d = c.t = this.t + a.t - b; for (c.s = 0; --d >= 0;) c[d] = 0; for (d = Math.max(b - this.t, 0) ; d this.t + d - b] = this.am(b - d, a[d], c, 0, 0, this.t + d - b); c.clamp(), c.drShiftTo(1, c) } function Barrett(a) { this.r2 = nbi(), this.q3 = nbi(), BigInteger.ONE.dlShiftTo(2 * a.t, this.r2), this.mu = this.r2.divide(a), this.m = a } function barrettConvert(a) { if (a.s  2 * this.m.t) return a.mod(this.m); if (a.compareTo(this.m) return a; var b = nbi(); return a.copyTo(b), this.reduce(b), b } function barrettRevert(a) { return a } function barrettReduce(a) { for (a.drShiftTo(this.m.t - 1, this.r2), a.t > this.m.t + 1 && (a.t = this.m.t + 1, a.clamp()), this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3), this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2) ; a.compareTo(this.r2) this.m.t + 1); for (a.subTo(this.r2, a) ; a.compareTo(this.m) >= 0;) a.subTo(this.m, a) } function barrettSqrTo(a, b) { a.squareTo(b), this.reduce(b) } function barrettMulTo(a, b, c) { a.multiplyTo(b, c), this.reduce(c) } function bnModPow(a, b) { var c, d, e = a.bitLength(), f = nbv(1); if (0 >= e) return f; c = 18 > e ? 1 : 48 > e ? 3 : 144 > e ? 4 : 768 > e ? 5 : 6, d = 8 > e ? new Classic(b) : b.isEven() ? new Barrett(b) : new Montgomery(b); var g = new Array, h = 3, i = c - 1, j = (1 if (g[1] = d.convert(this), c > 1) { var k = nbi(); for (d.sqrTo(g[1], k) ; j >= h;) g[h] = nbi(), d.mulTo(k, g[h - 2], g[h]), h += 2 } var l, m, n = a.t - 1, o = !0, p = nbi(); for (e = nbits(a[n]) - 1; n >= 0;) { for (e >= i ? l = a[n] >> e - i & j : (l = (a[n] & (1  0 && (l |= a[n - 1] >> this.DB + e - i)), h = c; 0 == (1 & l) ;) l >>= 1, --h; if ((e -= h) this.DB, --n), o) g[l].copyTo(f), o = !1; else { for (; h > 1;) d.sqrTo(f, p), d.sqrTo(p, f), h -= 2; h > 0 ? d.sqrTo(f, p) : (m = f, f = p, p = m), d.mulTo(p, g[l], f) } for (; n >= 0 && 0 == (a[n] & 1 this.DB - 1, --n) } return d.revert(f) } function bnGCD(a) { var b = this.s this.negate() : this.clone(), c = a.s if (b.compareTo(c) var d = b; b = c, c = d } var e = b.getLowestSetBit(), f = c.getLowestSetBit(); if (0 > f) return b; for (f > e && (f = e), f > 0 && (b.rShiftTo(f, b), c.rShiftTo(f, c)) ; b.signum() > 0;) (e = b.getLowestSetBit()) > 0 && b.rShiftTo(e, b), (e = c.getLowestSetBit()) > 0 && c.rShiftTo(e, c), b.compareTo(c) >= 0 ? (b.subTo(c, b), b.rShiftTo(1, b)) : (c.subTo(b, c), c.rShiftTo(1, c)); return f > 0 && c.lShiftTo(f, c), c } function bnpModInt(a) { if (0 >= a) return 0; var b = this.DV % a, c = this.s if (this.t > 0) if (0 == b) c = this[0] % a; else for (var d = this.t - 1; d >= 0; --d) c = (b * c + this[d]) % a; return c } function bnModInverse(a) { var b = a.isEven(); if (this.isEven() && b || 0 == a.signum()) return BigInteger.ZERO; for (var c = a.clone(), d = this.clone(), e = nbv(1), f = nbv(0), g = nbv(0), h = nbv(1) ; 0 != c.signum() ;) { for (; c.isEven() ;) c.rShiftTo(1, c), b ? (e.isEven() && f.isEven() || (e.addTo(this, e), f.subTo(a, f)), e.rShiftTo(1, e)) : f.isEven() || f.subTo(a, f), f.rShiftTo(1, f); for (; d.isEven() ;) d.rShiftTo(1, d), b ? (g.isEven() && h.isEven() || (g.addTo(this, g), h.subTo(a, h)), g.rShiftTo(1, g)) : h.isEven() || h.subTo(a, h), h.rShiftTo(1, h); c.compareTo(d) >= 0 ? (c.subTo(d, c), b && e.subTo(g, e), f.subTo(h, f)) : (d.subTo(c, d), b && g.subTo(e, g), h.subTo(f, h)) } return 0 != d.compareTo(BigInteger.ONE) ? BigInteger.ZERO : h.compareTo(a) >= 0 ? h.subtract(a) : h.signum() function bnIsProbablePrime(a) { var b, c = this.abs(); if (1 == c.t && c[0] for (b = 0; b if (c[0] == lowprimes[b]) return !0; return !1 } if (c.isEven()) return !1; for (b = 1; b for (var d = lowprimes[b], e = b + 1; e  d;) d *= lowprimes[e++]; for (d = c.modInt(d) ; e > b;) if (d % lowprimes[b++] == 0) return !1 } return c.millerRabin(a) } function bnpMillerRabin(a) { var b = this.subtract(BigInteger.ONE), c = b.getLowestSetBit(); if (0 >= c) return !1; var d = b.shiftRight(c); a = a + 1 >> 1, a > lowprimes.length && (a = lowprimes.length); for (var e = nbi(), f = 0; a > f; ++f) { e.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]); var g = e.modPow(d, this); if (0 != g.compareTo(BigInteger.ONE) && 0 != g.compareTo(b)) { for (var h = 1; h++ if (g = g.modPowInt(2, this), 0 == g.compareTo(BigInteger.ONE)) return !1; if (0 != g.compareTo(b)) return !1 } } return !0 } function Arcfour() { this.i = 0, this.j = 0, this.S = new Array } function ARC4init(a) { var b, c, d; for (b = 0; 256 > b; ++b) this.S[b] = b; for (c = 0, b = 0; 256 > b; ++b) c = c + this.S[b] + a[b % a.length] & 255, d = this.S[b], this.S[b] = this.S[c], this.S[c] = d; this.i = 0, this.j = 0 } function ARC4next() { var a; return this.i = this.i + 1 & 255, this.j = this.j + this.S[this.i] & 255, a = this.S[this.i], this.S[this.i] = this.S[this.j], this.S[this.j] = a, this.S[a + this.S[this.i] & 255] } function prng_newstate() { return new Arcfour } function rng_get_byte() { if (null == rng_state) { for (rng_state = prng_newstate() ; rng_psize > rng_pptr;) { var a = Math.floor(65536 * Math.random()); rng_pool[rng_pptr++] = 255 & a } for (rng_state.init(rng_pool), rng_pptr = 0; rng_pptr return rng_state.next() } function rng_get_bytes(a) { var b; for (b = 0; b function SecureRandom() { } function parseBigInt(a, b) { return new BigInteger(a, b) } function linebrk(a, b) { for (var c = "", d = 0; d + b return c + a.substring(d, a.length) } function byte2Hex(a) { return 16 > a ? "0" + a.toString(16) : a.toString(16) } function pkcs1pad2(a, b) { if (b return console.error("Message too long for RSA"), null; for (var c = new Array, d = a.length - 1; d >= 0 && b > 0;) { var e = a.charCodeAt(d--); 128 > e ? c[--b] = e : e > 127 && 2048 > e ? (c[--b] = 63 & e | 128, c[--b] = e >> 6 | 192) : (c[--b] = 63 & e | 128, c[--b] = e >> 6 & 63 | 128, c[--b] = e >> 12 | 224) } c[--b] = 0; for (var f = new SecureRandom, g = new Array; b > 2;) { for (g[0] = 0; 0 == g[0];) f.nextBytes(g); c[--b] = g[0] } return c[--b] = 2, c[--b] = 0, new BigInteger(c) } function RSAKey() { this.n = null, this.e = 0, this.d = null, this.p = null, this.q = null, this.dmp1 = null, this.dmq1 = null, this.coeff = null } function RSASetPublic(a, b) { null != a && null != b && a.length > 0 && b.length > 0 ? (this.n = parseBigInt(a, 16), this.e = parseInt(b, 16)) : console.error("Invalid RSA public key") } function RSADoPublic(a) { return a.modPowInt(this.e, this.n) } function RSAEncrypt(a) { var b = pkcs1pad2(a, this.n.bitLength() + 7 >> 3); if (null == b) return null; var c = this.doPublic(b); if (null == c) return null; var d = c.toString(16); return 0 == (1 & d.length) ? d : "0" + d } function pkcs1unpad2(a, b) { for (var c = a.toByteArray(), d = 0; d if (c.length - d != b - 1 || 2 != c[d]) return null; for (++d; 0 != c[d];) if (++d >= c.length) return null; for (var e = ""; ++d var f = 255 & c[d]; 128 > f ? e += String.fromCharCode(f) : f > 191 && 224 > f ? (e += String.fromCharCode((31 & f) return e } function RSASetPrivate(a, b, c) { null != a && null != b && a.length > 0 && b.length > 0 ? (this.n = parseBigInt(a, 16), this.e = parseInt(b, 16), this.d = parseBigInt(c, 16)) : console.error("Invalid RSA private key") } function RSASetPrivateEx(a, b, c, d, e, f, g, h) { null != a && null != b && a.length > 0 && b.length > 0 ? (this.n = parseBigInt(a, 16), this.e = parseInt(b, 16), this.d = parseBigInt(c, 16), this.p = parseBigInt(d, 16), this.q = parseBigInt(e, 16), this.dmp1 = parseBigInt(f, 16), this.dmq1 = parseBigInt(g, 16), this.coeff = parseBigInt(h, 16)) : console.error("Invalid RSA private key") } function RSAGenerate(a, b) { var c = new SecureRandom, d = a >> 1; this.e = parseInt(b, 16); for (var e = new BigInteger(b, 16) ; ;) { for (; this.p = new BigInteger(a - d, 1, c), 0 != this.p.subtract(BigInteger.ONE).gcd(e).compareTo(BigInteger.ONE) || !this.p.isProbablePrime(10) ;); for (; this.q = new BigInteger(d, 1, c), 0 != this.q.subtract(BigInteger.ONE).gcd(e).compareTo(BigInteger.ONE) || !this.q.isProbablePrime(10) ;); if (this.p.compareTo(this.q) var f = this.p; this.p = this.q, this.q = f } var g = this.p.subtract(BigInteger.ONE), h = this.q.subtract(BigInteger.ONE), i = g.multiply(h); if (0 == i.gcd(e).compareTo(BigInteger.ONE)) { this.n = this.p.multiply(this.q), this.d = e.modInverse(i), this.dmp1 = this.d.mod(g), this.dmq1 = this.d.mod(h), this.coeff = this.q.modInverse(this.p); break } } } function RSADoPrivate(a) { if (null == this.p || null == this.q) return a.modPow(this.d, this.n); for (var b = a.mod(this.p).modPow(this.dmp1, this.p), c = a.mod(this.q).modPow(this.dmq1, this.q) ; b.compareTo(c) this.p); return b.subtract(c).multiply(this.coeff).mod(this.p).multiply(this.q).add(c) } function RSADecrypt(a) { var b = parseBigInt(a, 16), c = this.doPrivate(b); return null == c ? null : pkcs1unpad2(c, this.n.bitLength() + 7 >> 3) } function hex2b64(a) { var b, c, d = ""; for (b = 0; b + 3 > 6) + b64map.charAt(63 & c); for (b + 1 == a.length ? (c = parseInt(a.substring(b, b + 1), 16), d += b64map.charAt(c > 2) + b64map.charAt((3 & c)  0;) d += b64pad; return d } function b64tohex(a) { var b, c, d = "", e = 0; for (b = 0; b > 2), c = 3 & v, e = 1) : 1 == e ? (d += int2char(c > 4), c = 15 & v, e = 2) : 2 == e ? (d += int2char(c), d += int2char(v >> 2), c = 3 & v, e = 3) : (d += int2char(c > 4), d += int2char(15 & v), e = 0)); return 1 == e && (d += int2char(c function b64toBA(a) { var b, c = b64tohex(a), d = new Array; for (b = 0; 2 * b return d } var dbits, canary = 0xdeadbeefcafe, j_lm = 15715070 == (16777215 & canary); j_lm && "Microsoft Internet Explorer" == navigator.appName ? (BigInteger.prototype.am = am2, dbits = 30) : j_lm && "Netscape" != navigator.appName ? (BigInteger.prototype.am = am1, dbits = 26) : (BigInteger.prototype.am = am3, dbits = 28), BigInteger.prototype.DB = dbits, BigInteger.prototype.DM = (1 var BI_FP = 52; BigInteger.prototype.FV = Math.pow(2, BI_FP), BigInteger.prototype.F1 = BI_FP - dbits, BigInteger.prototype.F2 = 2 * dbits - BI_FP; var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz", BI_RC = new Array, rr, vv; for (rr = "0".charCodeAt(0), vv = 0; 9 >= vv; ++vv) BI_RC[rr++] = vv; for (rr = "a".charCodeAt(0), vv = 10; 36 > vv; ++vv) BI_RC[rr++] = vv; for (rr = "A".charCodeAt(0), vv = 10; 36 > vv; ++vv) BI_RC[rr++] = vv; Classic.prototype.convert = cConvert, Classic.prototype.revert = cRevert, Classic.prototype.reduce = cReduce, Classic.prototype.mulTo = cMulTo, Classic.prototype.sqrTo = cSqrTo, Montgomery.prototype.convert = montConvert, Montgomery.prototype.revert = montRevert, Montgomery.prototype.reduce = montReduce, Montgomery.prototype.mulTo = montMulTo, Montgomery.prototype.sqrTo = montSqrTo, BigInteger.prototype.copyTo = bnpCopyTo, BigInteger.prototype.fromInt = bnpFromInt, BigInteger.prototype.fromString = bnpFromString, BigInteger.prototype.clamp = bnpClamp, BigInteger.prototype.dlShiftTo = bnpDLShiftTo, BigInteger.prototype.drShiftTo = bnpDRShiftTo, BigInteger.prototype.lShiftTo = bnpLShiftTo, BigInteger.prototype.rShiftTo = bnpRShiftTo, BigInteger.prototype.subTo = bnpSubTo, BigInteger.prototype.multiplyTo = bnpMultiplyTo, BigInteger.prototype.squareTo = bnpSquareTo, BigInteger.prototype.divRemTo = bnpDivRemTo, BigInteger.prototype.invDigit = bnpInvDigit, BigInteger.prototype.isEven = bnpIsEven, BigInteger.prototype.exp = bnpExp, BigInteger.prototype.toString = bnToString, BigInteger.prototype.negate = bnNegate, BigInteger.prototype.abs = bnAbs, BigInteger.prototype.compareTo = bnCompareTo, BigInteger.prototype.bitLength = bnBitLength, BigInteger.prototype.mod = bnMod, BigInteger.prototype.modPowInt = bnModPowInt, BigInteger.ZERO = nbv(0), BigInteger.ONE = nbv(1), NullExp.prototype.convert = nNop, NullExp.prototype.revert = nNop, NullExp.prototype.mulTo = nMulTo, NullExp.prototype.sqrTo = nSqrTo, Barrett.prototype.convert = barrettConvert, Barrett.prototype.revert = barrettRevert, Barrett.prototype.reduce = barrettReduce, Barrett.prototype.mulTo = barrettMulTo, Barrett.prototype.sqrTo = barrettSqrTo; var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997], lplim = (1 var rng_psize = 256, rng_state, rng_pool, rng_pptr; if (null == rng_pool) { rng_pool = new Array, rng_pptr = 0; var t; if (window.crypto && window.crypto.getRandomValues) { var z = new Uint32Array(256); for (window.crypto.getRandomValues(z), t = 0; t var onMouseMoveListener = function (a) { if (this.count = this.count || 0, this.count >= 256 || rng_pptr >= rng_psize) return void (window.removeEventListener ? window.removeEventListener("mousemove", onMouseMoveListener) : window.detachEvent && window.detachEvent("onmousemove", onMouseMoveListener)); this.count += 1; var b = a.x + a.y; rng_pool[rng_pptr++] = 255 & b }; window.addEventListener ? window.addEve


评论


亲,登录后才可以留言!