文档章节

JS加密解密

雨落秋垣
 雨落秋垣
发布于 2018/12/08 09:45
字数 1523
阅读 103
收藏 0

调用方法示例:

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<p id="a"></p>
		<p id="b"></p>
		<p id="c"></p>
	</body>
	<script type="text/javascript" src="js/keybase.js" ></script>
	<script>
		let a = '汪政..222RRRp767868^*%^*&%&344h哈哈';
		let b = udp.d(ud(a)); // 需要加密的内容
		let c = udp.p(up(b)); // 需要解密的内容
		window.document.getElementById('a').innerHTML = "加密前的内容是:" + a;
		window.document.getElementById('b').innerHTML = "加密后的内容是:" + b;
		window.document.getElementById('c').innerHTML = "解密后的内容是:" + c;
	</script>

</html>

需要引入的JS文件的代码(加解密方案):

function ud(r) {
	function t(r) {
		if(!r) return "";
		for(var t = "", n = 23115, e = 0; e < r.length; e++) {
			var o = r.charCodeAt(e),
				i = o ^ n;
			n = o, t += String.fromCharCode(i)
		}
		return t
	}

	function n(r) {
		if(!r) return "";
		for(var t = "", n = 71891, e = 0; e < r.length; e++) {
			var o = r.charCodeAt(e) ^ n;
			n = n * e % 256 + 2333, t += String.fromCharCode(o)
		}
		return t
	}

	function e(r) {
		if(!r) return "";
		for(var t = "", n = 39371, e = 0; e < r.length; e++) {
			var o = r.charCodeAt(e);
			o ^= "V587".charCodeAt(n = (n + 1) % "V587".length), t += String.fromCharCode(o)
		}
		return t
	}
	return btoa(encodeURIComponent(r)[function(r) {
		for(var e = "", o = 32799, i = 0; i < r.length; i++) {
			var f = r[t("\u5a28\u5a40\u5a21\u5a53\u5a10\u5a7f\u5a1b\u5a7e\u5a3f\u5a4b")](i);
			f ^= t("\u5a1d\u5a28\u5a10\u5a27").charCodeAt(o = (o + 1) % n("\u1885\u0928\u0902\u09a6").length), e += String.fromCharCode(f)
		}
		return e
	}("$PH[7V]")](new RegExp(e("s\x1dc\x07{\fy\x1a\x10hC\x05+\x1c"), "g"), function(r, t) {
		return String[function(r) {
			if(!r) return "";
			for(var t = "".split("").reverse().join(""), n = 18670, e = 0; e < r.length; e++) {
				var o = r.charCodeAt(e),
					i = o ^ n;
				n = o, t += String.fromCharCode(i)
			}
			return t
		}(e("\u48de\u48cf\u48ad\u48cf\u48ed\u48e6\u488a\u48f7\u48d5\u48d9\u48b0\u48da"))]("0x" + t)
	}))
}

function up(r) {
	var t = "T^";

	function n(r) {
		return r.split("").reverse().join("")
	}

	function e(r) {
		return r[o("%E" + t + '"')]("").reverse().join("")
	}

	function o(r) {
		if(!r) return "";
		for(var t = "", n = 39371, e = 0; e < r.length; e++) {
			var o = r.charCodeAt(e);
			o ^= "V587".charCodeAt(n = (n + 1) % "V587".length), t += String.fromCharCode(o)
		}
		return t
	}
	return decodeURIComponent(atob(r)[e("tilps")]("").map(function(r) {
		return "%" + ("00" + r.charCodeAt(0)[n("gnirtSot")](16)).slice(-2)
	}).join(e("")))
}! function(r, t, n, e, o) {
	! function(i, f, a, h, u, C, c) {
		var d = r[0],
			g = r[1],
			v = "fr",
			S = "om",
			l = "n",
			m = o[0],
			s = e[0],
			A = r[2];

		function p(t) {
			if(!t) return "";
			for(var e = n[0], o = r[3], i = n[1]; i < t.length; i++) {
				var f = t.charCodeAt(i) ^ o;
				o = o * i % 256 + n[2], e += String.fromCharCode(f)
			}
			return e
		}

		function y(r) {
			return r.split("").reverse().join("")
		}

		function V(r) {
			if(!r) return "";
			for(var t = e[1], n = 39371, o = 0; o < r.length; o++) {
				var i = r.charCodeAt(o);
				i ^= "V587".charCodeAt(n = (n + 1) % "V587".length), t += String.fromCharCode(i)
			}
			return t
		}! function(n, e) {
			var o = r[4],
				i = t[0],
				a = r[5];
			"function" == typeof define && define[r[6]] ? define([], e) : "object" == typeof module && module[o + d + i + "orts"] ? module[g + a + "s"] = e() : n[function(r) {
				if(!r) return f[0];
				for(var t = h[0], n = 18670, e = 0; e < r[y("htgnel")]; e++) {
					var o = r.charCodeAt(e),
						i = o ^ n;
					n = o, t += String.fromCharCode(i)
				}
				return t
			}(r[7])] = e()
		}(this, function() {
			var d = n[3],
				g = o[1],
				_ = "o",
				x = t[1],
				j = "gn",
				k = "ahCmo",
				R = "rf",
				E = e[2],
				w = r[8],
				N = r[9],
				b = n[4],
				O = V("\x1f}\x7fq\x13q{u\x17"),
				q = C[2],
				P = i[0],
				U = c[1],
				Y = i[1],
				H = f[r[10]];

			function I(t) {
				var n = r[11];
				if(!t) return "";
				for(var e = "", i = o[2], f = 0; f < t.length; f++) {
					var a = t.charCodeAt(f);
					a ^= "V587".charCodeAt(i = (i + 1) % "V587" [y("ht" + j + "el")]), e += String[y(n + k + R)](a)
				}
				return e
			}

			function L(r) {
				return r.split(V("")).reverse()[g + _ + x + l]("")
			}

			function Q() {
				var r = f[2];
				this[a[1]] = L(r + O)
			}

			function T(r) {
				var t = o[3],
					n = e[3];
				if(!r) return function(r) {
					if(!r) return "";
					for(var t = "", n = 23115, e = 0; e < r.length; e++) {
						var o = r.charCodeAt(e),
							i = o ^ n;
						n = o, t += String.fromCharCode(i)
					}
					return t
				}("");
				for(var i = V(""), f = 18670, a = 0; a < r[y("htgnel")]; a++) {
					var h = r.charCodeAt(a),
						u = h ^ f;
					f = h, i += String[v + S + d + t + n + "de"](u)
				}
				return i
			}

			function Z(r) {
				if(!r) return u[1];
				for(var t = "", n = c[3], e = c[4]; e < r.length; e++) {
					var i = r.charCodeAt(e) ^ n;
					n = n * e % o[4] + 2333, t += String.fromCharCode(i)
				}
				return t
			}
			return I(p(r[12])), Q[T(m + "\u48ec\u4895\u48e5\u4880")][f[3]] = function(e) {
				var i, f, a, h, c, d, g, v = C[3],
					S = V(""),
					l = 0;
				for(e = this[I("\t@LQnj\\")](e); l < e[T(p(t[2]))];) h = (i = e.charCodeAt(l++)) >> o[5], c = (3 & i) << 4 | (f = e.charCodeAt(l++)) >> 4, d = (r[13] & f) << 2 | (a = e[p(s + "\u09b5\u09c9")](l++)) >> 6, g = 63 & a, isNaN(f) ? d = g = 64 : isNaN(a) && (g = 64), S = S + this._keyStr[u[0]](h) + this[L(v + p("\u18b8\u0942"))][L(p("\u18a7\u095c\u0948\u09f0\u09b8\u093e"))](c) + this._keyStr.charAt(d) + this["_keySt" + q][n[5]](g);
				return S
			}, Q.prototype[Z("\u4333")] = function(t) {
				var o, u, C, d, g, v, S, l = e[4],
					m = a[2],
					s = p(""),
					y = 0;
				for(t = t[L("ecalper")](new RegExp(T("\u48b5\u48eb\u48aa\u4887\u48dd\u48bc\u4891\u48eb\u48db\u48f6\u48cf\u4893\u48b8\u48e4\u48cb\u4897\u48aa\u48f7"), f[4]), i[2]); y < t.length;) d = this[p("\u188c\u0976\u095f\u09e8\u0983\u0929\u099c")].indexOf(t[T(V("\u48db\u48d0\u48bc\u48c1\u48e1\u48f6"))](y++)), g = this[T(A + "\u4895\u48e1\u4893")].indexOf(t[I("5]YE" + m)](y++)), v = this["_key" + l + "r"].indexOf(t[T("\u488d\u48e5\u4884\u48f6\u48b7\u48c3")](y++)), S = this._keyStr[Z(a[3])](t[f[r[14]]](y++)), o = d << c[2] | g >> 4, u = (g & h[n[6]]) << n[7] | v >> 2, C = (3 & v) << 6 | S, s += String[h[r[15]]](o), n[8] != v && (s += String.fromCharCode(u)), 64 != S && (s += String[e[5]](C));
				return this._utf8_p(s)
			}, Q[i[3]]._utf8_d = function(e) {
				e = e[V("$PH[7V]")](new RegExp(h[o[6]], "g"), "\n");
				for(var u = "", C = 0; C < e.length; C++) {
					var c = e[T(y(E + w))](C);
					c < 128 ? u += String["fromCharCo" + P](c) : c > h[5] && c < 2048 ? (u += String.fromCharCode(c >> r[16] | 192), u += String[n[9]](r[17] & c | 128)) : (u += String[i[o[6]]](c >> 12 | 224), u += String.fromCharCode(c >> t[3] & i[5] | a[4]), u += String.fromCharCode(c & f[6] | 128))
				}
				return u
			}, Q["prot" + N + "e"][U + Y + H + y(r[18])] = function(o) {
				for(var f = "", h = 0, C = a[5], c = n[1], d = a[5]; h < o[T("\u4882\u48e7\u4889\u48ee" + b)];)(C = o[u[t[4]]](h)) < e[6] ? (f += String[T(u[3])](C), h++) : C > i[6] && C < 224 ? (c = o.charCodeAt(h + r[10]), f += String[p(e[7])]((31 & C) << 6 | 63 & c), h += 2) : (c = o[V("5]YE\x15Z\\R\x17A")](h + 1), d = o[p("\u18b0\u0975\u095b\u09e3\u0993\u0932\u098a\u09d4\u09b5\u09c9")](h + 2), f += String[r[19]]((C & u[4]) << 12 | (63 & c) << n[10] | 63 & d), h += 3);
				return f
			}, new Q
		})
	}(["de", "u", "", e[8], "fromCharCode", 63, 191], ["", "t", "=/+9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJ", "d", o[7], e[9], 63], ["", "_keyStr", "\x17A", "\u432a\u0973\u095e\u09f4\u09a8\u0912\u0988", 128, 0], ["", 2333, 15, e[5], "\\r\\n", 127], ["charAt", "", "charCodeAt", "\u4888\u48fa\u4895\u48f8\u48bb\u48d3\u48b2\u48c0\u4883\u48ec\u4888\u48ed", r[13]], ["", 0, "r", "rtSye"], ["V587", o[8], n[6], 82755, 0])
}(["x", "exp", "\u48b1\u48da\u48bf\u48c6", 71891, "e", "ort", "amd", "\u489b\u48ff\u488f", "\u48e5\u488d", "otyp", 1, "edoCr", "\u18f0\u095b\u0967\u0986\u09f5\u091c\u09a4\u09ef\u09c1\u09fc", 15, 5, 3, 6, 63, "p_8f", "fromCharCode"], ["p", "i", "\u5051\u41fa\u41b3\u417f\u414a\u41af", 6, 2], ["", 0, 2333, "Ch", "\u489a\u48f2", "charAt", 2, 4, 64, "fromCharCode", 6], ["\u18b0\u0975\u095b\u09e3\u0993\u0932\u098a\u09d4", "", "\u48ee\u489a\u48db\u48be\u48da\u48b5\u48f6\u4884", "Co", "St", "fromCharCode", 128, "\u18b5\u096f\u0955\u09fc\u0993\u0935\u098f\u09c3\u09b7\u09d2\u09a6\u09d4", "prototype", "charAt"], ["\u489e\u48ec\u4883\u48f7\u4898", "j", 32799, "ar", 256, 2, 4, "g", "_"]);

兼容性特别强,大家可以试试。

© 著作权归作者所有

雨落秋垣

雨落秋垣

粉丝 31
博文 8
码字总数 10382
作品 3
深圳
前端工程师
私信 提问
JS_七种JAVASCRIPT加密/解密方法

本文一共介绍了七种JAVASCRIPT加密方法。   一:最简单的加密解密   二:转义字符的妙用   三:使用Microsoft出品的脚本编码器Script Encoder来进行编码 (自创简单解码)   四:任意...

喵王不瞌睡
2014/12/29
342
0
JAVASCRIPT加密解密终级指南

Javascript加密方法:: p M0 v) Q% C* q' t$ S J- o& |0 K 一:最简单的加密解密 9 `7 J; P7 u& _! J 二:转义字符""的妙用2 n( U7 J8 L5 R1 E 三:使用microsoft出品的脚本编码器Script En......

晨曦之光
2012/05/16
148
0
c# .NET RSA结合AES加密服务端和客户端请求数据

这几天空闲时间就想研究一下加密,环境是web程序,通过js请求后台返回数据,我想做的事js在发送请求前将数据加密,服务端收到后解密,待服务端处理完请求后,将处理结果加密返回给客户端,客...

金同学
2018/08/02
0
0
前端加密解密之Crypto.js

前端js加密概述 对系统安全性要求比较高,那么需要选择https协议来传输数据。当然很多情况下一般的web网站,如果安全要求不是很高的话,用http协议就可以了。在这种情况下,密码的明文传输显...

梁青竹
2018/12/18
0
0
JavaScript加密库Crypto-JS的使用

先来图片一张,看看效果(一个采用Crypto-JS实现的工具展示): CryptoJS (crypto.js) 为 JavaScript 提供了各种各样的加密算法。目前已支持的算法包括: MD5 SHA-1 SHA-256 AES Rabbit MAR...

王振威
2012/07/30
33.8K
6

没有更多内容

加载失败,请刷新页面

加载更多

最简单的获取相机拍照的图片

  import android.content.Intent;import android.graphics.Bitmap;import android.os.Bundle;import android.os.Environment;import android.provider.MediaStore;import andr......

MrLins
58分钟前
4
0
说好不哭!数据可视化深度干货,前端开发下一个涨薪点在这里~

随着互联网在各行各业的影响不断深入,数据规模越来越大,各企业也越来越重视数据的价值。作为一家专业的数据智能公司,个推从消息推送服务起家,经过多年的持续耕耘,积累沉淀了海量数据,在...

个推
59分钟前
8
0
第三方支付-返回与回调注意事项

不管是支付宝,微信,还是其它第三方支付,第四方支付,支付机构服务商只要涉及到钱的交易都要进行如下校验,全部成功了才视为成功订单 1.http请求是否成功 2.校验商户号 3.校验订单号及状态...

Shingfi
今天
4
0
简述Java内存分配和回收策略以及Minor GC 和 Major GC(Full GC)

内存分配: 1. 栈区:栈可分为Java虚拟机和本地方法栈 2. 堆区:堆被所有线程共享,在虚拟机启动时创建,是唯一的目的是存放对象实例,是gc的主要区域。通常可分为两个区块年轻代和年老代。更...

DustinChan
今天
6
0
Excel插入批注:可在批注插入文字、形状、图片

1.批注一直显示:审阅选项卡-------->勾选显示批注选项: 2.插入批注快捷键:Shift+F2 组合键 3.在批注中插入图片:鼠标右键点击批注框的小圆点【重点不可以在批注文本框内点击】----->调出批...

东方墨天
今天
6
1

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部