Implement base64 md5 sha1 password encryption in javascript, base64sha1
1. base64 Encryption
Introduce the base64.js file to the page. The call method is as follows:
<! Doctype html>
2. md5 Encryption
REFERENCE The md5.js file on the page. The call method is
<! Doctype html>
3. sha1 Encryption
It is said that this is the most secure encryption
When sha1.js is introduced to the page, the call method is
<! Doctype html>
Very popular javascript md5 Encryption
I can see the MD5 encryption of javascript on the Internet. If it looks better, I will extract it for your reference.
<HTML> <HEAD> <META http-equiv = 'content-type' Content = 'text/html; charset = gb'> <TITLE> very popular JS md encryption method </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 compliance */var chrsz =;/* bits per input cha Racter. -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 */functio N 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,, x [I +],-); a = md_ff (a, B, c, d, x [I +],); d = md_ff (d,, 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,, x [I +],); a = md_hh (a, B, c, d, x [I +],-); d = md_hh (d,, 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,, x [I +],-); a = md_ii (a, B, c, d, x [I +],); d = md_ii (d,, 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_cen (q, a, B, x, s, t) {return safe_add (bit_rol (safe_add (a, q), safe_add (x, t )), S), B);} function md_ff (a, B, c, d, x, s, t) {return md_cen (B & c) | ((~ B) & d), a, B, x, s, t);} function md_gg (a, B, c, d, x, s, t) {return md_cen (B & d) | (c &(~ D), a, B, x, s, t);} function md_hh (a, B, c, d, x, s, t) {return md_cen (B ^ c ^ d, a, B, x, s, t);} function md_ii (a, B, c, d, x, s, t) {return md_cen (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. c Oncat (hash), +);}/** Add integers, wrapping at ^. this uses-bit operations internally * to work around the 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);}/** C Onvert 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>