function md5(string) {
var x = Array();
var k, AA, BB, CC, DD, a, b, c, d;
var S11 = , S12 = , S13 = , S14 = ;
var S21 = , S22 = , S23 = , S24 = ;
var S31 = , S32 = , S33 = , S34 = ;
var S41 = , S42 = , S43 = , S44 = ;
string = Utf8Encode(string);
x = ConvertToWordArray(string);
a = 0x67452301;
b = 0xEFCDAB89;
c = 0x98BADCFE;
d = 0x10325476;
for (k = ; k < x.length; k += ) {
AA = a;
BB = b;
CC = c;
DD = d;
a = FF(a, b, c, d, x[k + ], S11, 0xD76AA478);
d = FF(d, a, b, c, x[k + ], S12, 0xE8C7B756);
c = FF(c, d, a, b, x[k + ], S13, 0x242070DB);
b = FF(b, c, d, a, x[k + ], S14, 0xC1BDCEEE);
a = FF(a, b, c, d, x[k + ], S11, 0xF57C0FAF);
d = FF(d, a, b, c, x[k + ], S12, 0x4787C62A);
c = FF(c, d, a, b, x[k + ], S13, 0xA8304613);
b = FF(b, c, d, a, x[k + ], S14, 0xFD469501);
a = FF(a, b, c, d, x[k + ], S11, 0x698098D8);
d = FF(d, a, b, c, x[k + ], S12, 0x8B44F7AF);
c = FF(c, d, a, b, x[k + ], S13, 0xFFFF5BB1);
b = FF(b, c, d, a, x[k + ], S14, 0x895CD7BE);
a = FF(a, b, c, d, x[k + ], S11, 0x6B901122);
d = FF(d, a, b, c, x[k + ], S12, 0xFD987193);
c = FF(c, d, a, b, x[k + ], S13, 0xA679438E);
b = FF(b, c, d, a, x[k + ], S14, 0x49B40821);
a = GG(a, b, c, d, x[k + ], S21, 0xF61E2562);
d = GG(d, a, b, c, x[k + ], S22, 0xC040B340);
c = GG(c, d, a, b, x[k + ], S23, 0x265E5A51);
b = GG(b, c, d, a, x[k + ], S24, 0xE9B6C7AA);
a = GG(a, b, c, d, x[k + ], S21, 0xD62F105D);
d = GG(d, a, b, c, x[k + ], S22, 0x2441453);
c = GG(c, d, a, b, x[k + ], S23, 0xD8A1E681);
b = GG(b, c, d, a, x[k + ], S24, 0xE7D3FBC8);
a = GG(a, b, c, d, x[k + ], S21, 0x21E1CDE6);
d = GG(d, a, b, c, x[k + ], S22, 0xC33707D6);
c = GG(c, d, a, b, x[k + ], S23, 0xF4D50D87);
b = GG(b, c, d, a, x[k + ], S24, 0x455A14ED);
a = GG(a, b, c, d, x[k + ], S21, 0xA9E3E905);
d = GG(d, a, b, c, x[k + ], S22, 0xFCEFA3F8);
c = GG(c, d, a, b, x[k + ], S23, 0x676F02D9);
b = GG(b, c, d, a, x[k + ], S24, 0x8D2A4C8A);
a = HH(a, b, c, d, x[k + ], S31, 0xFFFA3942);
d = HH(d, a, b, c, x[k + ], S32, 0x8771F681);
c = HH(c, d, a, b, x[k + ], S33, 0x6D9D6122);
b = HH(b, c, d, a, x[k + ], S34, 0xFDE5380C);
a = HH(a, b, c, d, x[k + ], S31, 0xA4BEEA44);
d = HH(d, a, b, c, x[k + ], S32, 0x4BDECFA9);
c = HH(c, d, a, b, x[k + ], S33, 0xF6BB4B60);
b = HH(b, c, d, a, x[k + ], S34, 0xBEBFBC70);
a = HH(a, b, c, d, x[k + ], S31, 0x289B7EC6);
d = HH(d, a, b, c, x[k + ], S32, 0xEAA127FA);
c = HH(c, d, a, b, x[k + ], S33, 0xD4EF3085);
b = HH(b, c, d, a, x[k + ], S34, 0x4881D05);
a = HH(a, b, c, d, x[k + ], S31, 0xD9D4D039);
d = HH(d, a, b, c, x[k + ], S32, 0xE6DB99E5);
c = HH(c, d, a, b, x[k + ], S33, 0x1FA27CF8);
b = HH(b, c, d, a, x[k + ], S34, 0xC4AC5665);
a = II(a, b, c, d, x[k + ], S41, 0xF4292244);
d = II(d, a, b, c, x[k + ], S42, 0x432AFF97);
c = II(c, d, a, b, x[k + ], S43, 0xAB9423A7);
b = II(b, c, d, a, x[k + ], S44, 0xFC93A039);
a = II(a, b, c, d, x[k + ], S41, 0x655B59C3);
d = II(d, a, b, c, x[k + ], S42, 0x8F0CCC92);
c = II(c, d, a, b, x[k + ], S43, 0xFFEFF47D);
b = II(b, c, d, a, x[k + ], S44, 0x85845DD1);
a = II(a, b, c, d, x[k + ], S41, 0x6FA87E4F);
d = II(d, a, b, c, x[k + ], S42, 0xFE2CE6E0);
c = II(c, d, a, b, x[k + ], S43, 0xA3014314);
b = II(b, c, d, a, x[k + ], S44, 0x4E0811A1);
a = II(a, b, c, d, x[k + ], S41, 0xF7537E82);
d = II(d, a, b, c, x[k + ], S42, 0xBD3AF235);
c = II(c, d, a, b, x[k + ], S43, 0x2AD7D2BB);
b = II(b, c, d, a, x[k + ], S44, 0xEB86D391);
a = AddUnsigned(a, AA);
b = AddUnsigned(b, BB);
c = AddUnsigned(c, CC);
d = AddUnsigned(d, DD);
}
var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);
return temp.toUpperCase();
}
function RotateLeft(lValue, iShiftBits) {
return (lValue << iShiftBits) | (lValue >>> ( - iShiftBits));
}
function AddUnsigned(lX, lY) {
var lX4, lY4, lX8, lY8, lResult;
lX8 = (lX & 0x80000000);
lY8 = (lY & 0x80000000);
lX4 = (lX & 0x40000000);
lY4 = (lY & 0x40000000);
lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
if (lX4 & lY4) {
return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
}
if (lX4 | lY4) {
if (lResult & 0x40000000) {
return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
} else {
return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
}
} else {
return (lResult ^ lX8 ^ lY8);
}
}
function F(x, y, z) {
return (x & y) | ((~x) & z);
}
function G(x, y, z) {
return (x & z) | (y & (~z));
}
function H(x, y, z) {
return (x ^ y ^ z);
}
function I(x, y, z) {
return (y ^ (x | (~z)));
}
function FF(a, b, c, d, x, s, ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
function GG(a, b, c, d, x, s, ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
function HH(a, b, c, d, x, s, ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
function II(a, b, c, d, x, s, ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
function ConvertToWordArray(string) {
var lWordCount;
var lMessageLength = string.length;
var lNumberOfWords_temp1 = lMessageLength + ;
var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % )) / ;
var lNumberOfWords = (lNumberOfWords_temp2 + ) * ;
var lWordArray = Array(lNumberOfWords - );
var lBytePosition = ;
var lByteCount = ;
while (lByteCount < lMessageLength) {
lWordCount = (lByteCount - (lByteCount % )) / ;
lBytePosition = (lByteCount % ) * ;
lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
lByteCount++;
}
lWordCount = (lByteCount - (lByteCount % )) / ;
lBytePosition = (lByteCount % ) * ;
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
lWordArray[lNumberOfWords - ] = lMessageLength << ;
lWordArray[lNumberOfWords - ] = lMessageLength >>> ;
return lWordArray;
}
function WordToHex(lValue) {
var WordToHexValue = "", WordToHexValue_temp = "", lByte, lCount;
for (lCount = ; lCount <= ; lCount++) {
lByte = (lValue >>> (lCount * )) & ;
WordToHexValue_temp = "" + lByte.toString();
WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - , );
}
return WordToHexValue;
}
function Utf8Encode(string) {
var utftext = "";
for (var n = ; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < ) {
utftext += String.fromCharCode(c);
} else if ((c > ) && (c < )) {
utftext += String.fromCharCode((c >> ) | );
utftext += String.fromCharCode((c & ) | );
} else {
utftext += String.fromCharCode((c >> ) | );
utftext += String.fromCharCode(((c >> ) & ) | );
utftext += String.fromCharCode((c & ) | );
}
}
return utftext;
}
module.exports = {
md5: md5
}

路径图  在utils文件下新建一个md5.js

引用方式

var md5 = require('../../utils/md5.js');
md5.md5(string)

小程序md5加密的更多相关文章

  1. 微信小程序------MD5加密(支持中文和不支持中文)和网络请求(get和post)

    开发中常常遇到MD5加密,最近做小程序也用到了,简单总结了一下: 这要有两个加密文件,一个不支持中文,一个支持,所以你选择支持的来用就行了: 也随便说说小程序的get和post网络请求. 来看看效果图 ...

  2. 微信小程序Md5加密(utf-8汉字无影响)

    微信小程序不让使用第三方jqMD5 只好改原生js咯 废话不多说直接贴代码 其实就是将原生function调用改为 module.exports = md5; 文中 红色标注 使用方法 将md5.js ...

  3. 微信小程序AES加密解密

    微信小程序  其实在调用一些第三方 js的时候 其实没有大家想的那么复杂,无非就是把原生js调用方式   改为微信小程序 js调用方式 废话不多说直接贴代码 其实就是将原生function 或者 对象 ...

  4. 微信小程序des加密、PHP des解密

    最近在做对小程序传输数据进行加密,加密方法有很多,使用的是des对称加密 采用的是CBC模式, 引用的插件为tripledes.js,https://github.com/Favour1111in/h ...

  5. 小程序_RSA加密功能

    这是开发的第三个小程序,基于一个物流系统,简化功能开发下单流程.登录的时候,系统是使用RSA进行加解密的. 流程:第一个接口获取到后端传过来的密匙共钥(publicKey),通过公钥使用RSA加密密码 ...

  6. laravel 微信小程序登录 加密解密扩展包

    https://github.com/lanceWan/wxxcx 测试的时候一定要保证服务器的 appid  和客户端的appid一致 如果是切换测试 那么需要把本地的项目从微信小程序上面删除掉 再 ...

  7. 小程序 mcrypt加密拓展在php7.1 废弃 使用openssl替代方案

    原加密方法 使用mcrypt //获得16位随机字符串,填充到明文之前 $random = $this->getRandomStr(); $text = $random . pack(" ...

  8. 微信小程序支付步骤

    http://blog.csdn.net/wangsf789/article/details/53419781 最近开发微信小程序进入到支付阶段,一直以来从事App开发,所以支付流程还是熟记于心的.但 ...

  9. 微信小程序开发学习资料

    作者:初雪链接:https://www.zhihu.com/question/50907897/answer/128494332来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

随机推荐

  1. C# 链表反转

    链表反转分这么两种情况, 一种是链表头节点始终前置,那这时候需要传一个头节点特有的标记:(简称:头不转) HEAD->Test1->Test2->Test3->Test4 反转 ...

  2. 如何执行shell命令

    可使用 git 命令行来执行shell命令,如 D 盘下的一 shell 脚本 test.sh 如下: echo "Hello world" 打开命令行,输入命令执行: 转载请注明 ...

  3. shunting-yard 调度场算法、中缀表达式转逆波兰表达式

    中缀表达式 1*(2+3) 这就是一个中缀表达式,运算符在数字之间,计算机处理前缀表达式和后缀表达式比较容易,但处理中缀表达式却不太容易,因此,我们需要使用shunting-yard Algorith ...

  4. SuperSocket基础二

    SuperSocket基础(二)-----一个完整的SocketServer项目 由于时间关系未能及时更新,关于SuperSocket,对于初学者而言,一个SuperSock的Server真的不好写. ...

  5. idea用到的快捷键

    之前一直用的eclipse,早就听说idea更智能,更便捷,于是,下载了idea,然后再破解,现在就慢慢抛弃eclipse,平时就用idea进行编码. idea的快捷键与eclipse还是有较大不同, ...

  6. pickel加速caffe读图

    64*64*3小图(12KB),batchSize=128,训练样本100万, 全部load进来内存受不了,load一次需要大半天 训练时读入一个batch,ali云服务器上每个batch读入时间1. ...

  7. python selenium web自动化测试完整项目实例

    问题: 好多想不到的地方,中间经历了一次重构,好蛋疼: xpath定位使用的不够熟练,好多定位问题,只能靠强制等待解决: 存在功能重复的方法,因为xpath定位不同,只能分开写,有时间可以继续优化: ...

  8. PyTorch进行深度学习入门

    一.PyTorch是什么? 这是一个基于Python的科学计算软件包,针对两组受众: ①.NumPy的替代品,可以使用GPU的强大功能 ②.深入学习研究平台,提供最大的灵活性和速度 二.入门 ①.张量 ...

  9. maven 项目连接mysql8.0版本时的注意事项

    MySQL 8.0 正式版 8.0.11 已发布,官方表示 MySQL 8 要比 MySQL 5.7 快 2 倍,还带来了大量的改进和更快的性能! 以前的maven项目,要注意依赖的注入 查看pom. ...

  10. Tomcat 控制台UTF-8乱码问题

    1.修改cmd的编码格式 快捷键win+R打开运行程序,输入regedit打开注册表,找到以下路劲并且修改. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Comman ...