In order to prevent information from being intercepted when the user logs in, we should encrypt the user's password on the client. The browser is submitted to the server is encrypted information, even if it is blocked, the interception of information has been encrypted processing, now more secure encryption algorithm is MD5 encryption algorithm, although MD5 is a one-way encryption algorithm, but the web also cracked Web site, so in order to further improve security, Can be two times MD5 encryption, or combined with other encryption methods such as 3DES and other two times encryption.
The code is as follows:
JS version:
var hexcase = 0;function Hex_md5 (a) {if (A = = "") return A;return Rstr2hex (RSTR_MD5 (Str2rstr_utf8 (a)))}function Hex_hmac_m D5 (A, b) {return Rstr2hex (RSTR_HMAC_MD5 (Str2rstr_utf8 (a), Str2rstr_utf8 (b)))}function Md5_vm_test () {return hex_md5 (" ABC "). toLowerCase () = =" 900150983cd24fb0d6963f7d28e17f72 "}function rstr_md5 (a) {return binl2rstr (BINL_MD5 (rstr2binl (a), A.length * 8))}function Rstr_hmac_md5 (c, f) {var E = Rstr2binl (c), if (E.length > +) {e = Binl_md5 (E, c.length * 8 )}var A = array (+), D = Array (+), for (var b = 0; b <; b++) {a[b] = E[b] ^ 909522486;d[b] = E[b] ^ 1549556828}var g = Binl_md5 (A.concat (Rstr2binl (f)), + f.length * 8); return Binl2rstr (Binl_md5 (D.concat (g), + +))}function RSTR2 Hex (c) {try {hexcase} catch (g) {hexcase = 0}var f = hexcase? "0123456789ABCDEF": "0123456789abcdef"; var b = ""; var a;for (var d = 0; D < c.length; d++) {a = C.charcodeat (d); B + = F.charat ((a >>> 4) & + F.charat (A &)}return b}function Str2rstr_utf 8 (c){var b = ""; var d = -1;var A, e;while (++d < c.length) {a = C.charcodeat (d); e = d + 1 < c.length? C.charcodeat (d + 1): 0;if (55296 <= a && a <= 56319 && 56320 <= e && e <= 57343) {a = 65536 + ((A & 1023) << + (E & 1023);d ++}if (a <= 127) {b + = String.fromCharCode (a)} else {if (a < = 2047) {b + = String.fromCharCode (192 | ((a >>> 6) & 31), 128 | (A & 63))} else {if (a <= 65535) {b + = String.fromCharCode (224 | ((a >>>) & 15), 128 | ((a >>> 6) & 63), 128 | (A & 63))} else {if (a <= 2097151) {b + = String.fromCharCode (240 | ((a >>>) & 7), 128 | ((a >>>) & 63), 128 | ((a >>> 6) & 63), 128 | (A & 63)}}}}} return b}function Rstr2binl (b) {var a = Array (b.length >> 2); for (var c = 0; c < a.length; C + +) {A[c] = 0}for ( var c = 0; C < b.length * 8; c + = 8) {a[c >> 5] |= (B.charcodeat (C/8) & 255) << (c%)}return a}function Binl2rstr (b) {var a = ""; for (var c = 0; C < b.length * 32; c + = 8) {A + = String.fromCharCode ((b[c >> 5] >>> (c)) & 255)}return a}function binl_md5 (p, k) {P[k >> 5] |= << ((k)%);p [((((k + +) >>> 9) << 4) + +] = K;var O = 1732584193;var n = 271 733879;var m = -1732584194;var L = 271733878;for (var g = 0; g < p.length; G + = +) {var j = O;var H = n;var F = M;var E = L;o = md5_ff (o, N, M, L, P[g + 0], 7, -680876936), L = md5_ff (l, O, N, M, P[g + 1],, -389564586); m = md5_ff (M, L, O , N, P[g + 2], 606105819), n = md5_ff (n, M, L, O, P[g + 3], -1044525330); o = md5_ff (o, N, M, L, P[g + 4], 7, 17641 8897); l = md5_ff (l, O, N, M, P[g + 5], -1473231341, 1200080426), M = md5_ff (M, L, O, N, p[g + 6], +,); n = md5_ff (n, M, L, O, P[g + 7], -45705983); o = md5_ff (o, N, M, L, P[g + 8], 7, 1770035416); l = md5_ff (l, O, N, M, P[g + 9], 12, 19584 14417); m = md5_ff (M, L, O, N, P[g + ten], -42063); n = mD5_FF (N, M, L, O, P[g + one], -1990404162); o = md5_ff (o, N, M, L, P[g +), 7, 1804603682); l = md5_ff (l, O, N, M, p[g + [], -40341101); m = md5_ff (M, L, O, N, p[g + +), -1502002290) n = md5_ff (n, M, L, O, P[g + 15], 22, 1236535329) ; o = Md5_gg (o, N, M, L, P[g + 1], 5, -165796510), L = Md5_gg (l, O, N, M, P[g + 6], 9, -1069501632); m = Md5_gg (M, L, O, N, p [G + one], 643717713, n = Md5_gg (n, M, L, O, P[g + 0], -373897302), o = Md5_gg (o, N, M, L, P[g + 5], 5,-701558691); L = Md5_gg (l, O, N, M, P[g +), 9, 38016083); m = Md5_gg (M, L, O, N, P[g + [], -660478335); n = Md5_gg (n, M, L, O, p[ G + 4], -405537848); o = Md5_gg (o, N, M, L, P[g + 9], 5, 568446438); l = Md5_gg (l, O, N, m, p[g + +), 9, -1019803690); m = Md5_gg (M, L, O, N, p[g + 3], -187363961), n = Md5_gg (n, M, L, O, P[g + 8], 1163531501); o = Md5_gg (o, N, M, L, p[ g + [], 5, -1444681467); l = Md5_gg (l, O, N, M, P[g + 2], 9, -51403784); m = Md5_gg (M, L, O, N, p[g + 7], +, 1735328473); n = Md5_gg (n, M, L, O, p[g + [], -1926607734); o = md5_hh (o, N, M, L, P[g + 5], 4, -378558); l = md5_hh (l, O, N, M, P[g + 8], one, -2022574463); m = Md5_hh (M, L, O, N, P[g + one], 1839030562), n = md5_hh (n, M, L, O, p[g + +), -35309556); o = md5_hh (o, N, M, L, p [G + 1], 4, -1530992060); l = md5_hh (l, O, N, M, P[g + 4], one, 1272893353); m = md5_hh (M, L, O, N, p[g + 7], 16,-155497632) n = md5_hh (n, M, L, O, P[g + ten], -1094730640), o = md5_hh (o, N, M, L, P[g + [], 4, 681279174); l = md5_hh (l, O, N, M, P[g + 0], one, -358537222), M = md5_hh (M, L, O, N, p[g + 3], -722521979), n = md5_hh (n, M, L, O, P[g + 6], 23, 76029189) ; o = md5_hh (o, N, M, L, P[g + 9], 4, -640364487), L = md5_hh (l, O, N, M, P[g +), one, -421815835); m = md5_hh (M, L, O, N, P[g + [], 530742520), n = md5_hh (n, M, L, O, P[g + 2], -995338651); o = Md5_ii (o, N, M, L, P[g + 0], 6,-198630844) L = Md5_ii (l, O, N, M, P[g + 7], ten, 1126891415), M = Md5_ii (M, L, O, N, p[g + +), -1416354905) n = Md5_ii (n, M, L, O , P[g + 5], 21, 57434055) o = Md5_ii (o, N, M, L, P[g +), 6, 1700485571), L = Md5_ii (l, O, N, M, P[g + 3], ten, -1894986606); m = Md5_ii (M, L, O, N, P[g +], -1051523) n = Md5_ii (n, M, L, O, P[g + 1], -2054922799); o = Md5_ii (o, N, M, L, P[g + 8], 6, 18733133 L = Md5_ii (l, O, N, m, P[g + -1560198380], -30611744), M = Md5_ii (M, L, O, N, p[g + 6],); n = Md5_ii (n, M, L, O, P[g +], 1309151649); o = Md5_ii (o, N, M, L, P[g + 4], 6, -145523070); l = Md5_ii (l, O, N, m, P[g + 11], 10, 1120 210379); m = Md5_ii (M, L, O, N, p[g + 2], -343485551, 718787259), n = Md5_ii (n, M, L, O, P[g + 9],); o = Safe_add (o, J n = Safe_add (n, h); m = Safe_add (M, f); L = Safe_add (L, E)}return Array (o, N, M, L)}function md5_cmn (H, E, D, C, G, f) {re Turn Safe_add (Bit_rol (Safe_add (Safe_add (E, h), Safe_add (c, f)), G), D)}function md5_ff (g, F, K, J, E, I, h) {return md5_cm N ((f & k) | ((~f) & J), G, F, E, I, h)}function Md5_gg (g, F, K, J, E, I, h) {return md5_cmn ((F & j) | (K & (~j)), G, F, E, I, h)}fUnction md5_hh (g, F, K, J, E, I, h) {return md5_cmn (f ^ k ^ J, G, F, E, I, h)}function Md5_ii (g, F, K, J, E, I, h) {return Md5_cmn (k ^ (f | (~j)), G, F, E, I, h)}function Safe_add (A, D) {var c = (A & 65535) + (d & 65535); var B = (a >> +) + (d > >) + (c >> +); return (b << 16) | (C & 65535)} function Bit_rol (A, B) {return (a << b) | (A >>> (32-b))};
Java Edition (Code Source: http://www.cnblogs.com/computer-lzy/archive/2011/04/28/2031649.html):
Package Md5;import java.security.messagedigest;import java.security.nosuchalgorithmexception;/* * MD5 encryption algorithm */public Class MD5 {//global array private final static string[] strdigits = {"0", "1", "2", "3", "4", "5", "6", "7 "," 8 "," 9 "," a "," B "," C "," D "," E "," F "}; Public MD5 () {}//return form is numeric with string private static string bytetoarraystring (byte bbyte) {int iRet = Bbyte; System.out.println ("iret=" +iret); if (IRet < 0) {IRet + = 256; } int iD1 = IRET/16; int iD2 = iRet% 16; return STRDIGITS[ID1] + STRDIGITS[ID2]; }//Return form only for the number private static String Bytetonum (byte bbyte) {int iRet = Bbyte; System.out.println ("iret1=" + iRet); if (IRet < 0) {IRet + = 256; } return string.valueof (IRet); }//Convert byte array to 16 binary string private static string Bytetostring (byte[] bbyte) {StringBuffer sbuffer = new StringBuffer (); for (int i = 0; I &lT Bbyte.length; i++) {sbuffer.append (bytetoarraystring (Bbyte[i])); } return sbuffer.tostring (); public static string Getmd5code (String strobj) {string resultstring = null; try {resultstring = new String (strobj); MessageDigest MD = messagedigest.getinstance ("MD5"); Md.digest () The function returns a byte array that holds the result of the hash value resultstring = bytetostring (Md.digest (Strobj.getbytes ())); } catch (NoSuchAlgorithmException ex) {ex.printstacktrace (); } return resultstring; } public static void Main (string[] args) {MD5 getMD5 = new MD5 (); System.out.println (Getmd5.getmd5code (Getmd5.getmd5code ("aaaaaa")); }}
MD5 encryption Algorithm (Java and JS)