成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

js前端對(duì)表單的字段md5加密

antyiwei / 816人閱讀

摘要:用戶輸入密碼的時(shí)候,應(yīng)該在端先進(jìn)行加入,然后傳到后端,和數(shù)據(jù)庫(kù)比對(duì)。

用戶輸入密碼的時(shí)候,應(yīng)該在web端先進(jìn)行md5加入,然后傳到后端,和數(shù)據(jù)庫(kù)比對(duì)。

如果像下面這樣,將密碼明文傳送到php端再加密,就已經(jīng)晚了:

$password = md5($_POST["password"]);

上面在審查元素——Network,點(diǎn)擊剛才的動(dòng)作,http傳輸?shù)氖敲魑难?br>

需要引入md5.js(別人寫(xiě)的一個(gè)開(kāi)源的js,下面附上了,侵權(quán)刪)

# 實(shí)際還可以
md5.js  base64.js   sha1.js
表單提交示例


    
    
    
    


    

這樣用審查元素,查看network——Header,就只post密文了

可以使用如下幾種方式加密:
hex_md5("123456");
b64_md5("123456");
str_md5("123456");
hex_hmac_md5(code,code);
b64_hmac_md5(username,username);
str_hmac_md5(password,password);
附別人的 md5.js
/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 */

/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
 * These are the functions you"ll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

/*
 * Perform a simple self-test to see if the VM is working
 */
function md5_vm_test()
{
  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}

/*
 * Calculate the MD5 of an array of little-endian words, and a bit length
 */
function core_md5(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    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 md5_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 md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
 * Calculate the HMAC-MD5, of a key and some data
 */
function core_hmac_md5(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
 * Convert a string to an array of little-endian words
 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
 */
function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

/*
 * Convert an array of little-endian words to a string
 */
function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}

/*
 * Convert an array of little-endian words to a hex string.
 */
function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

/*
 * Convert an array of little-endian words to a base-64 string
 */
function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/101340.html

相關(guān)文章

  • 關(guān)于BBS一些功能性補(bǔ)充以及踩坑記錄(持續(xù)補(bǔ)充)

    摘要:聲明以下記錄了本人實(shí)驗(yàn)性地探索過(guò)程,不代表正確,請(qǐng)謹(jǐn)慎食用。取消注釋,并添加兩個(gè)屬性,。由于在中被設(shè)置成了的,所以并不適合加密存入。算法碰撞的可能性很小,因此基本可以保證和加密后都是獨(dú)一無(wú)二的,防止黑客用彩虹表爆表。 聲明:以下記錄了本人實(shí)驗(yàn)性地探索過(guò)程,不代表正確,請(qǐng)謹(jǐn)慎食用。也歡迎提出各種批評(píng)建議,幫助我改正錯(cuò)誤。謝謝! 1.注冊(cè) 注冊(cè)時(shí)在注冊(cè)的jsp頁(yè)面使用js函數(shù)進(jìn)行合法性驗(yàn)證...

    hightopo 評(píng)論0 收藏0
  • PHP_在線支付

    摘要:支付平臺(tái)支付成功后,會(huì)往網(wǎng)站的某個(gè)回調(diào)發(fā)送數(shù)據(jù)?;卣{(diào)接收數(shù)據(jù)并根據(jù)隊(duì)則,生成檢驗(yàn)串,并判斷合法性。返回散列值字符串。 基本介紹 用途廣泛,很多網(wǎng)站都繼承了在線支付功能,如paypal,網(wǎng)銀在線,易寶支付,支付寶,快錢等第三方平臺(tái). 原理 基本上,每個(gè)銀行都有自家的支付接口,為什么不直接連接到銀行的接口去支付,而需要通過(guò)第三方支付? 銀行眾多,每家的銀行用的技術(shù)不一樣,比如招行使用.n...

    Channe 評(píng)論0 收藏0
  • 安全開(kāi)發(fā)筆記

    摘要:登錄注冊(cè)安全風(fēng)險(xiǎn)登錄注冊(cè)的風(fēng)險(xiǎn)點(diǎn)主要有四個(gè)暴力破解撞庫(kù)遍歷注冊(cè)用戶批量注冊(cè)。引入了驗(yàn)證碼機(jī)制同樣引入了額外的安全風(fēng)險(xiǎn),比如短信驗(yàn)證碼的短信炸彈風(fēng)險(xiǎn)圖形驗(yàn)證碼的可繞過(guò)可識(shí)別等。 概述 很多技術(shù)研發(fā)不了解安全,也不重視安全,只有在自己的服務(wù)器被黑掉、被掛馬、被脫褲才想起關(guān)注安全,但是這個(gè)時(shí)候,技術(shù)架構(gòu)已經(jīng)成型、代碼已經(jīng)在線上穩(wěn)定運(yùn)行,再亡羊補(bǔ)牢,改代碼、改策略,往往成本巨大、確收效很低。所...

    Cruise_Chan 評(píng)論0 收藏0
  • 普通網(wǎng)站防暴力破解新設(shè)計(jì)

    摘要:前端防暴力破解的一個(gè)設(shè)計(jì)地址描述傳統(tǒng)的防范暴力破解的方法是在前端登錄頁(yè)面增加驗(yàn)證碼雖然能有一定程度效果但是用戶也跟著遭罪驗(yàn)證碼越復(fù)雜用戶登錄的失敗率越高于是最近我想了一個(gè)新的設(shè)計(jì)前端在登錄時(shí)采用解密的方式獲取密鑰把密鑰與表單以前發(fā)往后端用 前端防暴力破解的一個(gè)設(shè)計(jì) Demo 地址 https://github.com/GitHub-Laz... 描述 傳統(tǒng)的防范暴力破解的方法是在前端登...

    xiaochao 評(píng)論0 收藏0
  • 普通網(wǎng)站防暴力破解新設(shè)計(jì)

    摘要:前端防暴力破解的一個(gè)設(shè)計(jì)地址描述傳統(tǒng)的防范暴力破解的方法是在前端登錄頁(yè)面增加驗(yàn)證碼雖然能有一定程度效果但是用戶也跟著遭罪驗(yàn)證碼越復(fù)雜用戶登錄的失敗率越高于是最近我想了一個(gè)新的設(shè)計(jì)前端在登錄時(shí)采用解密的方式獲取密鑰把密鑰與表單以前發(fā)往后端用 前端防暴力破解的一個(gè)設(shè)計(jì) Demo 地址 https://github.com/GitHub-Laz... 描述 傳統(tǒng)的防范暴力破解的方法是在前端登...

    stackvoid 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

antyiwei

|高級(jí)講師

TA的文章

閱讀更多
最新活動(dòng)
閱讀需要支付1元查看
<