javascript实现base64 md5 sha1 密码加密

前端之家收集整理的这篇文章主要介绍了javascript实现base64 md5 sha1 密码加密前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、base64加密

  在页面中引入base64.js文件调用方法为:

<Meta charset="utf-8"> base64加密

2、md5加密

  在页面中引用md5.js文件调用方法

<Meta charset="utf-8"> md5加密

3、sha1加密

  据说这是最安全的加密

  页面中引入sha1.js,调用方法

<Meta charset="utf-8"> sha1加密

文章所包含的加密下载地址:

文件打包下载地址

下面给大家补充点知识:

非常流行的javascript的md5加密

在网上看到的javascript的MD5加密,看比较好,就摘录了,供参考

非常流行的JS的md加密办法 var hexcase = ; /* hex output format. - lowercase; - uppercase */ var bpad = ""; /* base- pad character. "=" for strict RFC compliance */ 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 compatibility - 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,-); c = md_ff(c,); b = md_ff(b,-); a = md_ff(a,); c = md_ff(c,-); b = md_ff(b,); d = md_ff(d,x[i+],); a = md_gg(a,-); d = md_gg(d,-); c = md_gg(c,); b = md_gg(b,-); a = md_gg(a,); c = md_gg(c,-); b = md_gg(b,); d = md_gg(d,-); a = md_hh(a,-); d = md_hh(d,-); c = md_hh(c,); b = md_hh(b,); c = md_hh(c,-); b = md_hh(b,); d = md_hh(d,); a = md_hh(a,-); a = md_ii(a,-); d = md_ii(d,); c = md_ii(c,-); b = md_ii(b,); d = md_ii(d,-); c = md_ii(c,); a = md_ii(a,); b = md_ii(b,-); a = safe_add(a,olda); b = safe_add(b,oldb); c = safe_add(c,oldc); d = safe_add(d,oldd); } return Array(a,d); } /* * These functions implement the four basic operations the algorithm uses. */ function md_cmn(q,x,s,t) { return safe_add(bit_rol(safe_add(safe_add(a,q),safe_add(x,t)),s),b); } function md_ff(a,t) { return md_cmn((b & c) | ((~b) & d),t); } function md_gg(a,t) { return md_cmn((b & d) | (c & (~d)),t); } function md_hh(a,t) { return md_cmn(b ^ c ^ d,t); } function md_ii(a,t) { return md_cmn(c ^ (b | (~d)),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,cnt) { return (num << cnt) | (num >>> ( - cnt)); } /* * 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; }

以上所述是小编给大家介绍的javascript实现base64 md5 sha1 密码加密。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持

原文链接:https://www.f2er.com/js/52439.html

猜你在找的JavaScript相关文章