欢迎光临,了解微信小程序开发,就上易用通!

微信小程序登录密码MD5加密

发布:2018-02-10 12:07浏览: 来源:网络 作者:cola


    在小程序中,页面的脚本逻辑是在JsCore中运行,JsCore是一个没有窗口对象的环境,所以不能在脚本中使用window,也无法在脚本中操作组件。zepto/jQuery 也无法使用,因为zepto/jquery 会使用到window对象和document对象。所以在微信小程序中不能使用jquery.md5.js对密码进行加密。下面我提供一种MD5.js加密实例,本实例先静态演示,后面再到小程序中演示。

    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 https://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
    





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。