PHP加密由javascript解密的例子

一般情况我们都是php加密再由php解密了,但是我的工作就碰到了必须由php加密然后由js来解密了,这种情况我找到一站长写的例子,非常的优秀下面我们一起来看看.

PHP加密函数,代码如下:

  1. <?php
  2. function strencode($string) {
  3. $string = base64_encode($string);
  4. $key = md5('just a test');
  5. $len = strlen($key);
  6. $code = '';
  7. for ($i = 0; $i < strlen($string); $i++) {
  8. $k = $i % $len;
  9. $code .= $string [$i] ^ $key [$k];
  10. }
  11. return base64_encode($code);
  12. }
  13. //开源代码phpfensi.com
  14. echo strencode('just a test');
  15. ?>

JS:解密,代码如下:

  1. <script src="md5.js"></script>
  2. <script src="base64.js"></script>
  3. <script>
  4. function strencode(string) {
  5. key =md5('just a test');
  6. string = Base64.decode(string);
  7. len = key.length;
  8. code = '';
  9. for (i = 0; i < string.length; i++) {
  10. k = i % len;
  11. code += String.fromCharCode(string.charCodeAt(i) ^ key.charCodeAt(k));
  12. }
  13. return Base64.decode(code);
  14. }
  15. alert(strencode('U1s1TFN3IQ0reTZbBgJlCA===='));
  16. </script>

js MD5,代码如下:

  1. /*
  2. * Configurable variables. You may need to tweak these to be compatible with
  3. * the server-side, but the defaults work in most cases.
  4. */
  5. var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
  6. var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
  7. /*
  8. * These are the functions you'll usually want to call
  9. * They take string arguments and return either hex or base-64 encoded strings
  10. */
  11. function md5(s) {
  12. return rstr2hex(rstr_md5(str2rstr_utf8(s)));
  13. }
  14. function b64_md5(s) {
  15. return rstr2b64(rstr_md5(str2rstr_utf8(s)));
  16. }
  17. function any_md5(s, e) {
  18. return rstr2any(rstr_md5(str2rstr_utf8(s)), e);
  19. }
  20. function hex_hmac_md5(k, d)
  21. {
  22. return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
  23. }
  24. function b64_hmac_md5(k, d)
  25. {
  26. return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
  27. }
  28. function any_hmac_md5(k, d, e)
  29. {
  30. return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e);
  31. }
  32. /*
  33. * Perform a simple self-test to see if the VM is working
  34. */
  35. function md5_vm_test()
  36. {
  37. return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
  38. }
  39. /*
  40. * Calculate the MD5 of a raw string
  41. */
  42. function rstr_md5(s)
  43. {
  44. return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
  45. }
  46. /*
  47. * Calculate the HMAC-MD5, of a key and some data (raw strings)
  48. */
  49. function rstr_hmac_md5(key, data)
  50. {
  51. var bkey = rstr2binl(key);
  52. if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8);
  53. var ipad = Array(16), opad = Array(16);
  54. for(var i = 0; i < 16; i++)
  55. {
  56. ipad[i] = bkey[i] ^ 0x36363636;
  57. opad[i] = bkey[i] ^ 0x5C5C5C5C;
  58. }
  59. var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
  60. return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
  61. }
  62. /*
  63. * Convert a raw string to a hex string
  64. */
  65. function rstr2hex(input)
  66. {
  67. try {
  68. hexcase
  69. } catch(e) {
  70. hexcase=0;
  71. }
  72. var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  73. var output = "";
  74. var x;
  75. for(var i = 0; i < input.length; i++)
  76. {
  77. x = input.charCodeAt(i);
  78. output += hex_tab.charAt((x >>> 4) & 0x0F)
  79. + hex_tab.charAt( x & 0x0F);
  80. }
  81. return output;
  82. }
  83. /*
  84. * Convert a raw string to a base-64 string
  85. */
  86. function rstr2b64(input)
  87. {
  88. try {
  89. b64pad
  90. } catch(e) {
  91. b64pad='';
  92. }
  93. var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  94. var output = "";
  95. var len = input.length;
  96. for(var i = 0; i < len; i += 3)
  97. {
  98. var triplet = (input.charCodeAt(i) << 16)
  99. | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
  100. | (i + 2 < len ? input.charCodeAt(i+2) : 0);
  101. for(var j = 0; j < 4; j++)
  102. {
  103. if(i * 8 + j * 6 > input.length * 8) output += b64pad;
  104. else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
  105. }
  106. }
  107. return output;
  108. }
  109. /*
  110. * Convert a raw string to an arbitrary string encoding
  111. */
  112. function rstr2any(input, encoding)
  113. {
  114. var divisor = encoding.length;
  115. var i, j, q, x, quotient;
  116. /* Convert to an array of 16-bit big-endian values, forming the dividend */
  117. var dividend = Array(Math.ceil(input.length / 2));
  118. for(i = 0; i < dividend.length; i++)
  119. {
  120. dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
  121. }
  122. /*
  123. * Repeatedly perform a long division. The binary array forms the dividend,
  124. * the length of the encoding is the divisor. Once computed, the quotient
  125. * forms the dividend for the next step. All remainders are stored for later
  126. * use.
  127. */
  128. var full_length = Math.ceil(input.length * 8 /
  129. (Math.log(encoding.length) / Math.log(2)));
  130. var remainders = Array(full_length);
  131. for(j = 0; j < full_length; j++)
  132. {
  133. quotient = Array();
  134. x = 0;
  135. for(i = 0; i < dividend.length; i++)
  136. {
  137. x = (x << 16) + dividend[i];
  138. q = Math.floor(x / divisor);
  139. x -= q * divisor;
  140. if(quotient.length > 0 || q > 0)
  141. quotient[quotient.length] = q;
  142. }
  143. remainders[j] = x;
  144. dividend = quotient;
  145. }
  146. /* Convert the remainders to the output string */
  147. var output = "";
  148. for(i = remainders.length - 1; i >= 0; i--)
  149. output += encoding.charAt(remainders[i]);
  150. return output;
  151. }
  152. /*
  153. * Encode a string as utf-8.
  154. * For efficiency, this assumes the input is valid utf-16.
  155. */
  156. function str2rstr_utf8(input)
  157. {
  158. var output = "";
  159. var i = -1;
  160. var x, y;
  161. while(++i < input.length)
  162. {
  163. /* Decode utf-16 surrogate pairs */
  164. x = input.charCodeAt(i);
  165. y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
  166. if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
  167. {
  168. x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
  169. i++;
  170. }
  171. /* Encode output as utf-8 */
  172. if(x <= 0x7F)
  173. output += String.fromCharCode(x);
  174. else if(x <= 0x7FF)
  175. output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
  176. 0x80 | ( x & 0x3F));
  177. else if(x <= 0xFFFF)
  178. output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
  179. 0x80 | ((x >>> 6 ) & 0x3F),
  180. 0x80 | ( x & 0x3F));
  181. else if(x <= 0x1FFFFF)
  182. output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
  183. 0x80 | ((x >>> 12) & 0x3F),
  184. 0x80 | ((x >>> 6 ) & 0x3F),
  185. 0x80 | ( x & 0x3F));
  186. }
  187. return output;
  188. }
  189. /*
  190. * Encode a string as utf-16
  191. */
  192. function str2rstr_utf16le(input)
  193. {
  194. var output = "";
  195. for(var i = 0; i < input.length; i++)
  196. output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
  197. (input.charCodeAt(i) >>> 8) & 0xFF);
  198. return output;
  199. }
  200. function str2rstr_utf16be(input)
  201. {
  202. var output = "";
  203. for(var i = 0; i < input.length; i++)
  204. output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
  205. input.charCodeAt(i) & 0xFF);
  206. return output;
  207. }
  208. /*
  209. * Convert a raw string to an array of little-endian words
  210. * Characters >255 have their high-byte silently ignored.
  211. */
  212. function rstr2binl(input)
  213. {
  214. var output = Array(input.length >> 2);
  215. for(var i = 0; i < output.length; i++)
  216. output[i] = 0;
  217. for(var i = 0; i < input.length * 8; i += 8)
  218. output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
  219. return output;
  220. }
  221. /*
  222. * Convert an array of little-endian words to a string
  223. */
  224. function binl2rstr(input)
  225. {
  226. var output = "";
  227. for(var i = 0; i < input.length * 32; i += 8)
  228. output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
  229. return output;
  230. }
  231. /*
  232. * Calculate the MD5 of an array of little-endian words, and a bit length.
  233. */
  234. function binl_md5(x, len)
  235. {
  236. /* append padding */
  237. x[len >> 5] |= 0x80 << ((len) % 32);
  238. x[(((len + 64) >>> 9) << 4) + 14] = len;
  239. var a = 1732584193;
  240. var b = -271733879;
  241. var c = -1732584194;
  242. var d = 271733878;
  243. for(var i = 0; i < x.length; i += 16)
  244. {
  245. var olda = a;
  246. var oldb = b;
  247. var oldc = c;
  248. var oldd = d;
  249. a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  250. d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  251. c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
  252. b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  253. a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  254. d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
  255. c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  256. b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  257. a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
  258. d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  259. c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  260. b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  261. a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
  262. d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  263. c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  264. b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
  265. a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  266. d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  267. c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
  268. b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  269. a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  270. d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
  271. c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  272. b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  273. a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
  274. d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  275. c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  276. b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
  277. a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  278. d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  279. c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
  280. b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  281. a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  282. d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  283. c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
  284. b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  285. a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  286. d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
  287. c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  288. b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  289. a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
  290. d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  291. c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  292. b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
  293. a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  294. d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  295. c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
  296. b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  297. a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  298. d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
  299. c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  300. b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  301. a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
  302. d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  303. c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  304. b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  305. a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
  306. d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  307. c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  308. b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
  309. a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  310. d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  311. c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
  312. b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  313. a = safe_add(a, olda);
  314. b = safe_add(b, oldb);
  315. c = safe_add(c, oldc);
  316. d = safe_add(d, oldd);
  317. }
  318. return Array(a, b, c, d);
  319. }
  320. /*
  321. * These functions implement the four basic operations the algorithm uses.
  322. */
  323. function md5_cmn(q, a, b, x, s, t)
  324. {
  325. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  326. }
  327. function md5_ff(a, b, c, d, x, s, t)
  328. {
  329. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  330. }
  331. function md5_gg(a, b, c, d, x, s, t)
  332. {
  333. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  334. }
  335. function md5_hh(a, b, c, d, x, s, t)
  336. {
  337. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  338. }
  339. function md5_ii(a, b, c, d, x, s, t)
  340. {
  341. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  342. }
  343. /*
  344. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  345. * to work around bugs in some JS interpreters.
  346. */
  347. function safe_add(x, y)
  348. {
  349. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  350. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  351. return (msw << 16) | (lsw & 0xFFFF);
  352. }
  353. /*
  354. * Bitwise rotate a 32-bit number to the left.
  355. */
  356. function bit_rol(num, cnt)
  357. {
  358. return (num << cnt) | (num >>> (32 - cnt));
  359. }

js base64,代码如下:

  1. (function(global) {
  2. 'use strict';
  3. // existing version for noConflict()
  4. var _Base64 = global.Base64;
  5. var version = "2.1.4";
  6. // if node.js, we use Buffer
  7. var buffer;
  8. if (typeof module !== 'undefined' && module.exports) {
  9. buffer = require('buffer').Buffer;
  10. }
  11. // constants
  12. var b64chars
  13. = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  14. var b64tab = function(bin) {
  15. var t = {};
  16. for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i;
  17. return t;
  18. }(b64chars);
  19. var fromCharCode = String.fromCharCode;
  20. // encoder stuff
  21. var cb_utob = function(c) {
  22. if (c.length < 2) {
  23. var cc = c.charCodeAt(0);
  24. return cc < 0x80 ? c
  25. : cc < 0x800 ? (fromCharCode(0xc0 | (cc >>> 6))
  26. + fromCharCode(0x80 | (cc & 0x3f)))
  27. : (fromCharCode(0xe0 | ((cc >>> 12) & 0x0f))
  28. + fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
  29. + fromCharCode(0x80 | ( cc & 0x3f)));
  30. } else {
  31. var cc = 0x10000
  32. + (c.charCodeAt(0) - 0xD800) * 0x400
  33. + (c.charCodeAt(1) - 0xDC00);
  34. return (fromCharCode(0xf0 | ((cc >>> 18) & 0x07))
  35. + fromCharCode(0x80 | ((cc >>> 12) & 0x3f))
  36. + fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
  37. + fromCharCode(0x80 | ( cc & 0x3f)));
  38. }
  39. };
  40. var re_utob = /[uD800-uDBFF][uDC00-uDFFFF]|[^x00-x7F]/g;
  41. var utob = function(u) {
  42. return u.replace(re_utob, cb_utob);
  43. };
  44. var cb_encode = function(ccc) {
  45. var padlen = [0, 2, 1][ccc.length % 3],
  46. ord = ccc.charCodeAt(0) << 16
  47. | ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8)
  48. | ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)),
  49. chars = [
  50. b64chars.charAt( ord >>> 18),
  51. b64chars.charAt((ord >>> 12) & 63),
  52. padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63),
  53. padlen >= 1 ? '=' : b64chars.charAt(ord & 63)
  54. ];
  55. return chars.join('');
  56. };
  57. var btoa = global.btoa ? function(b) {
  58. return global.btoa(b);
  59. } : function(b) {
  60. return b.replace(/[sS]{1,3}/g, cb_encode);
  61. };
  62. var _encode = buffer
  63. ? function (u) {
  64. return (new buffer(u)).toString('base64')
  65. }
  66. : function (u) {
  67. return btoa(utob(u))
  68. }
  69. ;
  70. var encode = function(u, urisafe) {
  71. return !urisafe
  72. ? _encode(u)
  73. : _encode(u).replace(/[+/]/g, function(m0) {
  74. return m0 == '+' ? '-' : '_';
  75. }).replace(/=/g, '');
  76. };
  77. var encodeURI = function(u) {
  78. return encode(u, true)
  79. };
  80. // decoder stuff
  81. var re_btou = new RegExp([
  82. '[xC0-xDF][x80-xBF]',
  83. '[xE0-xEF][x80-xBF]{2}',
  84. '[xF0-xF7][x80-xBF]{3}'
  85. ].join('|'), 'g');
  86. var cb_btou = function(cccc) {
  87. switch(cccc.length) {
  88. case 4:
  89. var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
  90. | ((0x3f & cccc.charCodeAt(1)) << 12)
  91. | ((0x3f & cccc.charCodeAt(2)) << 6)
  92. | (0x3f & cccc.charCodeAt(3)),
  93. offset = cp - 0x10000;
  94. return (fromCharCode((offset >>> 10) + 0xD800)
  95. + fromCharCode((offset & 0x3FF) + 0xDC00));
  96. case 3:
  97. return fromCharCode(
  98. ((0x0f & cccc.charCodeAt(0)) << 12)
  99. | ((0x3f & cccc.charCodeAt(1)) << 6)
  100. | (0x3f & cccc.charCodeAt(2))
  101. );
  102. default:
  103. return fromCharCode(
  104. ((0x1f & cccc.charCodeAt(0)) << 6)
  105. | (0x3f & cccc.charCodeAt(1))
  106. );
  107. }
  108. };
  109. var btou = function(b) {
  110. return b.replace(re_btou, cb_btou);
  111. };
  112. var cb_decode = function(cccc) {
  113. var len = cccc.length,
  114. padlen = len % 4,
  115. n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0)
  116. | (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0)
  117. | (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0)
  118. | (len > 3 ? b64tab[cccc.charAt(3)] : 0),
  119. chars = [
  120. fromCharCode( n >>> 16),
  121. fromCharCode((n >>> 8) & 0xff),
  122. fromCharCode( n & 0xff)
  123. ];
  124. chars.length -= [0, 0, 2, 1][padlen];
  125. return chars.join('');
  126. };
  127. var atob = global.atob ? function(a) {
  128. return global.atob(a);
  129. } : function(a){
  130. return a.replace(/[sS]{1,4}/g, cb_decode);
  131. };
  132. var _decode = buffer
  133. ? function(a) {
  134. return (new buffer(a, 'base64')).toString()
  135. }
  136. : function(a) {
  137. return btou(atob(a))
  138. };
  139. var decode = function(a){
  140. return _decode(
  141. a.replace(/[-_]/g, function(m0) {
  142. return m0 == '-' ? '+' : '/'
  143. })
  144. .replace(/[^A-Za-z0-9+/]/g, '')
  145. );
  146. };
  147. var noConflict = function() {
  148. var Base64 = global.Base64;
  149. global.Base64 = _Base64;
  150. return Base64;
  151. };
  152. // export Base64
  153. global.Base64 = {
  154. VERSION: version,
  155. atob: atob,
  156. btoa: btoa,
  157. fromBase64: decode,
  158. toBase64: encode,
  159. utob: utob,
  160. encode: encode,
  161. encodeURI: encodeURI,
  162. btou: btou,
  163. decode: decode,
  164. noConflict: noConflict
  165. };
  166. // if ES5 is available, make Base64.extendString() available
  167. if (typeof Object.defineProperty === 'function') {
  168. var noEnum = function(v){
  169. return {
  170. value:v,
  171. enumerable:false,
  172. writable:true,
  173. configurable:true
  174. };
  175. };
  176. global.Base64.extendString = function () {
  177. Object.defineProperty(
  178. String.prototype, 'fromBase64', noEnum(function () {
  179. return decode(this)
  180. }));
  181. Object.defineProperty(
  182. String.prototype, 'toBase64', noEnum(function (urisafe) {
  183. return encode(this, urisafe)
  184. }));
  185. Object.defineProperty(
  186. String.prototype, 'toBase64URI', noEnum(function () {
  187. return encode(this, true)
  188. }));
  189. };
  190. }
  191. // that's it!
  192. })(this);

最后把下面的很长的js分别保存为base64.js文件与md5.js文件,然后在要解密的文件中加载这两个js即可.