VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > python教程 >
  • python入门教程之js加密(十四)mail.yw.gov.cn/ RSA(2)

本站最新发布   Python从入门到精通|Python基础教程
试听地址  
https://www.xin3721.com/eschool/pythonxin3721/


this.i]; this.S[this.i] = this.S[this.j]; this.S[this.j] = a; return this.S[(a + this.S[this.i]) & 255]; } Arcfour.prototype.init = ARC4init; Arcfour.prototype.next = ARC4next; function prng_newstate() { return new Arcfour(); } var rng_psize = 256; var rng_state; var rng_pool; var rng_pptr; function rng_seed_int(a) { rng_pool[rng_pptr++] ^= a & 255; rng_pool[rng_pptr++] ^= (a >> 8) & 255; rng_pool[rng_pptr++] ^= (a >> 16) & 255; rng_pool[rng_pptr++] ^= (a >> 24) & 255; if (rng_pptr >= rng_psize) rng_pptr -= rng_psize; } function rng_seed_time() { rng_seed_int(new Date().getTime()); } if (rng_pool == null) { rng_pool = new Array(); rng_pptr = 0; var t; if (navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) { var z = window.crypto.random(32); for (t = 0; t < z.length; ++t) rng_pool[rng_pptr++] = z.charCodeAt(t) & 255; } while (rng_pptr < rng_psize) { t = Math.floor(65536 * Math.random()); rng_pool[rng_pptr++] = t >>> 8; rng_pool[rng_pptr++] = t & 255; } rng_pptr = 0; rng_seed_time(); } function rng_get_byte() { if (rng_state == null) { rng_seed_time(); rng_state = prng_newstate(); rng_state.init(rng_pool); for (rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr) rng_pool[rng_pptr] = 0; rng_pptr = 0; } return rng_state.next(); } function rng_get_bytes(a) { var b; for (b = 0; b < a.length; ++b) a[b] = rng_get_byte(); } function SecureRandom() {} SecureRandom.prototype.nextBytes = rng_get_bytes; function parseBigInt(b, a) { return new BigInteger(b, a); } function linebrk(d, b) { var c = ""; var a = 0; while (a + b < d.length) { c += d.substring(a, a + b) + "\n"; a += b; } return c + d.substring(a, d.length); } function byte2Hex(a) { if (a < 0x10) return "0" + a.toString(16); else return a.toString(16); } function pkcs1pad2(e, c) { if (c < e.length + 11) { alert("Message too long for RSA"); return null; } var a = new Array(); var b = e.length - 1; while (b >= 0 && c > 0) a[--c] = e.charCodeAt(b--); a[--c] = 0; var d = new SecureRandom(); var f = new Array(); while (c > 2) { f[0] = 0; while (f[0] == 0) d.nextBytes(f); a[--c] = f[0]; } a[--c] = 2; a[--c] = 0; return new BigInteger(a); } 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(b, a) { if (b != null && a != null && b.length > 0 && a.length > 0) { this.n = parseBigInt(b, 16); this.e = parseInt(a, 16); } else alert("Invalid RSA public key"); } function RSADoPublic(a) { return a.modPowInt(this.e, this.n); } function RSAEncrypt(e) { var d = pkcs1pad2(e, (this.n.bitLength() + 7) >> 3); if (d == null) return null; var a = this.doPublic(d); if (a == null) return null; var b = a.toString(16); if ((b.length & 1) == 0) return b; else return "0" + b; } RSAKey.prototype.doPublic = RSADoPublic; RSAKey.prototype.setPublic = RSASetPublic; RSAKey.prototype.encrypt = RSAEncrypt; var b64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var b64pad = "="; function hex2b64(b) { var d; var a; var e = ""; for (d = 0; d + 3 <= b.length; d += 3) { a = parseInt(b.substring(d, d + 3), 16); e += b64map.charAt(a >> 6) + b64map.charAt(a & 63); } if (d + 1 == b.length) { a = parseInt(b.substring(d, d + 1), 16); e += b64map.charAt(a << 2); } else if (d + 2 == b.length) { a = parseInt(b.substring(d, d + 2), 16); e += b64map.charAt(a >> 2) + b64map.charAt((a & 3) << 4); } while ((e.length & 3) > 0) e += b64pad; return e; } function b64tohex(d) { var c = ""; var a; var b = 0; var e; for (a = 0; a < d.length; ++a) { if (d.charAt(a) == b64pad) break; v = b64map.indexOf(d.charAt(a)); if (v < 0) continue; if (b == 0) { c += int2char(v >> 2); e = v & 3; b = 1; } else if (b == 1) { c += int2char((e << 2) | (v >> 4)); e = v & 0xf; b = 2; } else if (b == 2) { c += int2char(e); c += int2char(v >> 2); e = v & 3; b = 3; } else { c += int2char((e << 2) | (v >> 4)); c += int2char(v & 0xf); b = 0; } } if (b == 1) c += int2char(e << 2); return c; } function b64toBA(e) { var c = b64tohex(e); var d; var b = new Array(); for (d = 0; 2 * d < c.length; ++d) { b[d] = parseInt(c.substring(2 * d, 2 * d + 2), 16); } return b; } function safeauth_js() {} function getPwd(pwd) { var PublicKey = "CF87D7B4C864F4842F1D337491A48FFF54B73A17300E8E42FA365420393AC0346AE55D8AFAD975DFA175FAF0106CBA81AF1DDE4ACEC284DAC6ED9A0D8FEB1CC070733C58213EFFED46529C54CEA06D774E3CC7E073346AEBD6C66FC973F299EB74738E400B22B1E7CDC54E71AED059D228DFEB5B29C530FF341502AE56DDCFE9"; var RSA = new RSAKey(); RSA.setPublic(PublicKey, "10001"); var PublicTs = "1578280046"; var Res = RSA.encrypt(pwd + '\n' + PublicTs + '\n'); return hex2b64(Res); }
复制代码

结果:

相关教程
        
关于我们--广告服务--免责声明--本站帮助-友情链接--版权声明--联系我们       黑ICP备07002182号