javascript实现base64 md5 sha1 密码加密
网络编程 2021-07-04 21:03www.168986.cn编程入门
本篇文章给大家介绍了javascript实现密码加密,通过base64、md5、sha1文件,调用相关方法实现密码加密,非常简单,需要的朋友可以参考下
1、base64加密
在页面中引入base64.js文件,调用方法为
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>base64加密</title> <script type="text/javascript" src="base64.js"></script> <script type="text/javascript"> var b = new Base64(); var str = b.encode("admin:admin"); alert("base64 encode:" + str); //解密 str = b.decode(str); alert("base64 decode:" + str); </script> </head> <body> </body> </html>
2、md5加密
在页面中引用md5.js文件,调用方法为
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>md5加密</title> <script type="text/ecmascript" src="md5.js"></script> <script type="text/javascript"> var hash = hex_md5("123dafd"); alert(hash) </script> </head> <body> </body> </html>
3、sha1加密
据说这是最安全的加密
页面中引入sha1.js,调用方法为
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>sha1加密</title> <script type="text/ecmascript" src="sha1.js"></script> <script type="text/javascript"> var sha = hex_sha1('mima123465') alert(sha) </script> </head> <body> </body> </html>
文章所包含的加密下载地址
狼蚁网站SEO优化给大家补充点知识非常流行的javascript的md5加密
在网上看到的javascript的MD5加密,看比较好,就摘录了,供参考
<HTML> <HEAD> <META http-equiv='Content-Type' content='text/html; charset=gb'> <TITLE>非常流行的JS的md加密办法</TITLE> </HEAD> <BODY > <input id=test value=webasp> <input type=button value=md onclick="alert(hex_md(test.value))"> <script> var hexcase = ; / hex output format. - lowercase; - uppercase / var bpad = ""; / base- pad character. "=" for strict RFC pliance / var chrsz = ; / bits per input character. - ASCII; - Unicode / / These are the functions you'll usually want to call They take string arguments and return either hex or base- encoded strings / function hex_md(s){ return binlhex(core_md(strbinl(s), s.length chrsz));} function b_md(s){ return binlb(core_md(strbinl(s), s.length chrsz));} function hex_hmac_md(key, data) { return binlhex(core_hmac_md(key, data)); } function b_hmac_md(key, data) { return binlb(core_hmac_md(key, data)); } / Backwards patibility - same as hex_md() / function calcMD(s){ return binlhex(core_md(strbinl(s), s.length chrsz));} / Perform a simple self-test to see if the VM is working / function md_vm_test() { return hex_md("abc") == "cdfbdfdef"; } / Calculate the MD of an array of little-endian words, and a bit length / function core_md(x, len) { / append padding / x[len >> ] |= x << ((len) % ); x[(((len + ) >>> ) << ) + ] = len; var a = ; var b = -; var c = -; var d = ; for(var i = ; i < x.length; i += ) { var olda = a; var oldb = b; var oldc = c; var oldd = d; a = md_ff(a, b, c, d, x[i+ ], , -); d = md_ff(d, a, b, c, x[i+ ], , -); c = md_ff(c, d, a, b, x[i+ ], , ); b = md_ff(b, c, d, a, x[i+ ], , -); a = md_ff(a, b, c, d, x[i+ ], , -); d = md_ff(d, a, b, c, x[i+ ], , ); c = md_ff(c, d, a, b, x[i+ ], , -); b = md_ff(b, c, d, a, x[i+ ], , -); a = md_ff(a, b, c, d, x[i+ ], , ); d = md_ff(d, a, b, c, x[i+ ], , -); c = md_ff(c, d, a, b, x[i+], , -); b = md_ff(b, c, d, a, x[i+], , -); a = md_ff(a, b, c, d, x[i+], , ); d = md_ff(d, a, b, c, x[i+], , -); c = md_ff(c, d, a, b, x[i+], , -); b = md_ff(b, c, d, a, x[i+], , ); a = md_gg(a, b, c, d, x[i+ ], , -); d = md_gg(d, a, b, c, x[i+ ], , -); c = md_gg(c, d, a, b, x[i+], , ); b = md_gg(b, c, d, a, x[i+ ], , -); a = md_gg(a, b, c, d, x[i+ ], , -); d = md_gg(d, a, b, c, x[i+], , ); c = md_gg(c, d, a, b, x[i+], , -); b = md_gg(b, c, d, a, x[i+ ], , -); a = md_gg(a, b, c, d, x[i+ ], , ); d = md_gg(d, a, b, c, x[i+], , -); c = md_gg(c, d, a, b, x[i+ ], , -); b = md_gg(b, c, d, a, x[i+ ], , ); a = md_gg(a, b, c, d, x[i+], , -); d = md_gg(d, a, b, c, x[i+ ], , -); c = md_gg(c, d, a, b, x[i+ ], , ); b = md_gg(b, c, d, a, x[i+], , -); a = md_hh(a, b, c, d, x[i+ ], , -); d = md_hh(d, a, b, c, x[i+ ], , -); c = md_hh(c, d, a, b, x[i+], , ); b = md_hh(b, c, d, a, x[i+], , -); a = md_hh(a, b, c, d, x[i+ ], , -); d = md_hh(d, a, b, c, x[i+ ], , ); c = md_hh(c, d, a, b, x[i+ ], , -); b = md_hh(b, c, d, a, x[i+], , -); a = md_hh(a, b, c, d, x[i+], , ); d = md_hh(d, a, b, c, x[i+ ], , -); c = md_hh(c, d, a, b, x[i+ ], , -); b = md_hh(b, c, d, a, x[i+ ], , ); a = md_hh(a, b, c, d, x[i+ ], , -); d = md_hh(d, a, b, c, x[i+], , -); c = md_hh(c, d, a, b, x[i+], , ); b = md_hh(b, c, d, a, x[i+ ], , -); a = md_ii(a, b, c, d, x[i+ ], , -); d = md_ii(d, a, b, c, x[i+ ], , ); c = md_ii(c, d, a, b, x[i+], , -); b = md_ii(b, c, d, a, x[i+ ], , -); a = md_ii(a, b, c, d, x[i+], , ); d = md_ii(d, a, b, c, x[i+ ], , -); c = md_ii(c, d, a, b, x[i+], , -); b = md_ii(b, c, d, a, x[i+ ], , -); a = md_ii(a, b, c, d, x[i+ ], , ); d = md_ii(d, a, b, c, x[i+], , -); c = md_ii(c, d, a, b, x[i+ ], , -); b = md_ii(b, c, d, a, x[i+], , ); a = md_ii(a, b, c, d, x[i+ ], , -); d = md_ii(d, a, b, c, x[i+], , -); c = md_ii(c, d, a, b, x[i+ ], , ); b = md_ii(b, c, d, a, x[i+ ], , -); a = safe_add(a, olda); b = safe_add(b, oldb); c = safe_add(c, oldc); d = safe_add(d, oldd); } return Array(a, b, c, d); } / These functions implement the four basic operations the algorithm uses. / function md_cmn(q, a, b, x, s, t) { return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); } function md_ff(a, b, c, d, x, s, t) { return md_cmn((b & c) | ((~b) & d), a, b, x, s, t); } function md_gg(a, b, c, d, x, s, t) { return md_cmn((b & d) | (c & (~d)), a, b, x, s, t); } function md_hh(a, b, c, d, x, s, t) { return md_cmn(b ^ c ^ d, a, b, x, s, t); } function md_ii(a, b, c, d, x, s, t) { return md_cmn(c ^ (b | (~d)), a, b, x, s, t); } / Calculate the HMAC-MD, of a key and some data / function core_hmac_md(key, data) { var bkey = strbinl(key); if(bkey.length > ) bkey = core_md(bkey, key.length chrsz); var ipad = Array(), opad = Array(); for(var i = ; i < ; i++) { ipad[i] = bkey[i] ^ x; opad[i] = bkey[i] ^ xCCCC; } var hash = core_md(ipad.concat(strbinl(data)), + data.length chrsz); return core_md(opad.concat(hash), + ); } / Add integers, wrapping at ^. This uses -bit operations internally to work around bugs in some JS interpreters. / function safe_add(x, y) { var lsw = (x & xFFFF) + (y & xFFFF); var msw = (x >> ) + (y >> ) + (lsw >> ); return (msw << ) | (lsw & xFFFF); } / Bitwise rotate a -bit number to the left. / function bit_rol(num, t) { return (num << t) | (num >>> ( - t)); } / Convert a string to an array of little-endian words If chrsz is ASCII, characters > have their hi-byte silently ignored. / function strbinl(str) { var bin = Array(); var mask = ( << chrsz) - ; for(var i = ; i < str.length chrsz; i += chrsz) bin[i>>] |= (str.charCodeAt(i / chrsz) & mask) << (i%); return bin; } / Convert an array of little-endian words to a hex string. / function binlhex(binarray) { var hex_tab = hexcase ? "ABCDEF" : "abcdef"; var str = ""; for(var i = ; i < binarray.length ; i++) { str += hex_tab.charAt((binarray[i>>] >> ((i%)+)) & xF) + hex_tab.charAt((binarray[i>>] >> ((i%) )) & xF); } return str; } / Convert an array of little-endian words to a base- string / function binlb(binarray) { var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; var str = ""; for(var i = ; i < binarray.length ; i += ) { var triplet = (((binarray[i >> ] >> ( i %)) & xFF) << ) | (((binarray[i+ >> ] >> ((i+)%)) & xFF) << ) | ((binarray[i+ >> ] >> ((i+)%)) & xFF); for(var j = ; j < ; j++) { if(i + j > binarray.length ) str += bpad; else str += tab.charAt((triplet >> (-j)) & xF); } } return str; } </script> </BODY></HTML>
以上所述是长沙网络推广给大家介绍的javascript实现base64 md5 sha1 密码加密,希望对大家有所帮助,如果大家有任何疑问请给我留言,长沙网络推广会及时回复大家的。在此也非常感谢大家对狼蚁SEO网站的支持!
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程