小程序模板網(wǎng)

微信小程序登錄密碼MD5加密

發(fā)布時(shí)間:2018-02-10 12:07 所屬欄目:小程序開發(fā)教程

    在小程序中,頁面的腳本邏輯是在JsCore中運(yùn)行,JsCore是一個(gè)沒有窗口對(duì)象的環(huán)境,所以不能在腳本中使用window,也無法在腳本中操作組件。zepto/jQuery 也無法使用,因?yàn)閦epto/jquery 會(huì)使用到window對(duì)象和document對(duì)象。所以在微信小程序中不能使用jquery.md5.js對(duì)密碼進(jìn)行加密。下面我提供一種MD5.js加密實(shí)例,本實(shí)例先靜態(tài)演示,后面再到小程序中演示。

    md5.js程序如下:

 

[javascript] view plain copy
 
  1. /* 
     * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message 
     * Digest Algorithm, as defined in RFC 1321. 
     * Version 1.1 Copyright (C) Paul Johnston 1999 - 2002. 
     * Code also contributed by Greg Holt 
     * See http://pajhome.org.uk/site/legal.html for details. 
     */  
      
    /* 
     * 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 rol(num, cnt)  
    {  
      return (num << cnt) | (num >>> (32 - cnt))  
    }  
      
    /* 
     * These functions implement the four basic operations the algorithm uses. 
     */  
    function cmn(q, a, b, x, s, t)  
    {  
      return safe_add(rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b)  
    }  
    function ff(a, b, c, d, x, s, t)  
    {  
      return cmn((b & c) | ((~b) & d), a, b, x, s, t)  
    }  
    function gg(a, b, c, d, x, s, t)  
    {  
      return cmn((b & d) | (c & (~d)), a, b, x, s, t)  
    }  
    function
    


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.u-renovate.com/wxmini/doc/course/21979.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢
AI智能客服 ×