jsencrypt参数前端加密c#解密.docx
《jsencrypt参数前端加密c#解密.docx》由会员分享,可在线阅读,更多相关《jsencrypt参数前端加密c#解密.docx(32页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、写程序时一般是通过form表单或者ajax方式将参数提交到服务器进行验证,如何防止提交的请求不被抓包后串改,虽然无法说绝对平安却给非法提交 提高了难度,本篇采用jsencypt在前端进行加密的并且用C#在后端解密,在 投票提交分数等H5应用上可以使用的上,并且进行简单的封装。l.demo H52的后台 话;白屋一卜,你就先追且531t式* 旦M也告退后台 。滋号公众平台Text to encrypt:name:password:submit(16) function pkcslpad2(a, b) if (b =0 & b 0;) var e =a.charCodeAt(d一); 128 e
2、? c-b = e :e 127 & 2048 e ? (cb= 63 &e| 128, cb= e 6 | 192) : (cb= 63 &e | 128, cb = e 6 & 63|128, cb =e 12 | 224) cb =0; for(varf = new SecureRandom, g = new Array; b 2;) for (g0 = 0; 0 =g0 ;)f. nextBytes(g) ; c-b = g0 return c-b= 2, c一b= 0, new Biginteger(c) f unction RSAKey () this, n = null, thi
3、s, e = 0, this, d = null, this, p = null, thi s.q = null, this, dmpl = null, this, dmql = null, this, coeff = null function RS ASetPublic(a, b) null != a & null != b & a. length 0 & b.length 0 ? (th is. n = parseBiglnt (a, 16), this, e = parselnt (b, 16) : console, error (z,Inval i d R SA public key
4、) function RSADoPublic (a) return a. modPowInt(this, e, this.n) function RSAEncrypt (a) var b = pkcslpad2 (a, this. n. bitLengthO + 7 3); if (null= b) return null; var c= this. doPublic(b); if(null = c) returnnul1; var d= c.toString(16);return0 = (1 & d. length) ? d : 0 + d functionpkcslunpad2(a, b)
5、 for (var c 二 a. toByteArray(),d = 0;d = c. length)returnnull; for (var e = ;+d f ?e += String. fromCharCode(f) :f 191 & 224 f?(e += String. fromCharCode(31 & f) 0 & b.length 0 ? (this.n 二 parseBiglnt(a, 16), this, e = parselnt(b, 16), this, d = parseBiglnt (c, 16) : console, error (Invalid RSA priv
6、ate key) funct ion RSASetPrivateEx(a, b, c, d, e, f, g, h) null != a & null != b & a. lengt h 0 & b.length 0 ? (this.n = parseBiglnt(a, 16), this.e = parselnt(b, 16), this. d = parseBiglnt (c, 16), this.p = parseBiglnt (d, 16), this.q 二 parseBiglnt (e, 16), this. dmpl 二 parseBiglnt(f, 16), this. dmq
7、l = parseBiglnt(g, 16), this.c oeff = parseBiglnt (h, 16) : console, error (/zInvalid RSA private key) functio n RSAGenerate (a, b) var c = new SecureRandom, d = a 1; this, e = parselnt (b, 16); for (var e = new Biginteger(b, 16) ; ;) for (; this, p = new Biglnteg er(a - d, 1, c), 0 != this. p. subt
8、ract(BigTnteger. ONE). gcd(e). compareTo(Biglnteg er. 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) = 0) var f = thi s
9、. 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). compare? o(Biginteger. ONE) this, n = this.p. multiply(this, q), this, d = e. modlnverse (i), this, dmpl = this. d. mod(g), this, dmql ; this
10、. d. mod(h), this, coeff 二 this. q. modlnverse(this, p); break function RSADoPrivate(a) if (null 二二 this, pnull = this, q) return a. modPow(this. d, this, n) ; for (var b = a. mod (this, p). m odPow(this. dmpl, this, p), c = a. mod (this, q). modPow(this, dmql, this, q) ; b. compa reTo(c) 3) functio
11、n hex2b64(a) var b, c, d = ; for (b = 0; b + 3 = a. length; b += 3) c = parselnt(a. substring(b, b + 3), 16), d += b64map.charAt (c 6) +b64map. charAt(63 & c); for (b +1 =a. length?(c = parselnt(a. substring(b, b + 1), 16), d += b64map. charAt(c 2) + b64map.charAt(3 & c) 0;) d += b64pad; return d fu
12、nction b 64tohex(a) varb, c, d = ,e = 0; for (b = 0;b a. length& a. charAt(b) !=b64pad; +b) v= b64map. indexOf(a. charAt(b), v 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
13、= 0);return1 = e &(d+二 int2char(c2), d function b64toBA(a) var b, c =b64tohex(a), d = new Array; for (b = 0; 2 * b c. length; +b) db = parselnt(c. subs tring(2 * b, 2 * b + 2), 16); return d var dbits, canary = Oxdeadbeefcafe, j_ Im 二 15715070 二二(16777215 & canary); j_lm & Microsoft Internet Explore
14、r”二 navigator. appName ? (Biginteger, prototype, am = am2, dbits = 30) : j_lm & Nets cape != navigator. appName ? (Biginteger, prototype, am = ami, dbits = 26) : (Big Integer, prototype, am = am3, dbits = 28), Biginteger, prototype. DB = dbits, Bigin teger. prototype. DM = (1 dbits) - 1, Biginteger,
15、 prototype. DV = 1 = vv; +vv) BI _RCrr+= vv; for (rr = a. charCod eAt (0), vv = 10; 36 vv; +vv) Bl RCrr+ = vv; for (rr = A. charCodeAt(0), vv = 10; 36 vv; +vv) BI_RCrr+ = vv; Classic, prototype, convert = cConvert,Classic. prototype, revert = cRevert, Classic, prototype, reduce = cReduce, Classi c.
16、prototype. mulTo = cMulTo, Classic, prototype. sqrTo = cSqrTo, Montgomery, protot ype.convert = montConvert, Montgomery, prototype, revert = montRevert, Montgomer y.prototype.reduce = montReduce, Montgomery, prototype. mulTo = montMulTo, Montgo mery. prototype. sqrTo = montSqrTo, Biginteger, prototy
17、pe. copyTo = bnpCopyTo, Bigl nteger.prototype, fromlnt = bnpFromlnt, Biginteger, prototype. fromString = bnpFro mString, Biginteger, prototype, clamp = bnpClamp, Biginteger, prototype. dlShiftTo 二 bnpDLShiftTo, Biginteger, prototype. drShiftTo = bnpDRShiftTo, Biginteger, proto type. IShiftTo = bnpLS
18、hiftTo, Biginteger, prototype. rShiftTo = bnpRShiftTo, Bigin teger. prototype.subTo = bnpSubTo, Biginteger, prototype. multiplyTo = bnpMultiply To, Biginteger, prototype. squareTo = bnpSquareTo, Biginteger, prototype. divRemTo =bnpDivRemTo, Biginteger, prototype. invDigit = bnpInvDigit, Biginteger,
19、prototyp e. isEven = bnpIsEven, Biginteger. prototype.exp = bnpExp, Biginteger, prototype, t oString = bnToString, Biginteger, prototype.negate = bnNegate, Biginteger.protot ype.abs = bnAbs, Biginteger, prototype. compareTo = bnCompareTo, Biginteger, proto type. bitLength = bnBitLength, Biginteger,
20、prototype, mod = bnMod, Biginteger.prot otype. modPowInt = bnModPowInt, Biginteger. ZERO = nbv (0), Biginteger. ONE = nbv (1), NullExp. prototype, convert = nNop, NullExp. prototype, revert = nNop, NullEx p. prototype. mulTo = nMulTo, NullExp. prototype. sqrTo = nSqrTo, Barrett, prototyp e.convert =
21、 barrettConvert, Barrett, prototype, revert = barrettRevert, Barrett, p rototype.reduce = barrettReduce, Barrett, prototype. mulTo = barrettMulTo, Barret t. 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,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- jsencrypt 参数 前端 加密 c# 解密
限制150内