小程序md5加密
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
引用方式
小程序md5加密的更多相关文章
- 微信小程序------MD5加密(支持中文和不支持中文)和网络请求(get和post)
开发中常常遇到MD5加密,最近做小程序也用到了,简单总结了一下: 这要有两个加密文件,一个不支持中文,一个支持,所以你选择支持的来用就行了: 也随便说说小程序的get和post网络请求. 来看看效果图 ...
- 微信小程序Md5加密(utf-8汉字无影响)
微信小程序不让使用第三方jqMD5 只好改原生js咯 废话不多说直接贴代码 其实就是将原生function调用改为 module.exports = md5; 文中 红色标注 使用方法 将md5.js ...
- 微信小程序AES加密解密
微信小程序 其实在调用一些第三方 js的时候 其实没有大家想的那么复杂,无非就是把原生js调用方式 改为微信小程序 js调用方式 废话不多说直接贴代码 其实就是将原生function 或者 对象 ...
- 微信小程序des加密、PHP des解密
最近在做对小程序传输数据进行加密,加密方法有很多,使用的是des对称加密 采用的是CBC模式, 引用的插件为tripledes.js,https://github.com/Favour1111in/h ...
- 小程序_RSA加密功能
这是开发的第三个小程序,基于一个物流系统,简化功能开发下单流程.登录的时候,系统是使用RSA进行加解密的. 流程:第一个接口获取到后端传过来的密匙共钥(publicKey),通过公钥使用RSA加密密码 ...
- laravel 微信小程序登录 加密解密扩展包
https://github.com/lanceWan/wxxcx 测试的时候一定要保证服务器的 appid 和客户端的appid一致 如果是切换测试 那么需要把本地的项目从微信小程序上面删除掉 再 ...
- 小程序 mcrypt加密拓展在php7.1 废弃 使用openssl替代方案
原加密方法 使用mcrypt //获得16位随机字符串,填充到明文之前 $random = $this->getRandomStr(); $text = $random . pack(" ...
- 微信小程序支付步骤
http://blog.csdn.net/wangsf789/article/details/53419781 最近开发微信小程序进入到支付阶段,一直以来从事App开发,所以支付流程还是熟记于心的.但 ...
- 微信小程序开发学习资料
作者:初雪链接:https://www.zhihu.com/question/50907897/answer/128494332来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
随机推荐
- Rsync数据同步工具
Rsync数据同步工具 什么是Rsync? Rsync是一款开源的.快速的.多功能的,可以实现全量及增量的本地或原程数据同步备份 ...
- (转载记录)Active Directory 灾难恢复
部分适用于Windows Server 2003. 在IT环境中谁也不能保证软硬件永远没有故障:那么就需要我们IT能够未雨绸缪,尽量避免故障发生,如果故障发生了,我们需要把损失降到最小:那么就需要我们 ...
- Vue 服务端渲染(SSR)
什么是服务端渲染? 简单理解是将组件或页面通过服务器生成html字符串,再发送到浏览器,最后将静态标记"混合"为客户端上完全交互的应用程序. 服务端渲染的优点 更好的SEO,搜索引 ...
- 整理的Python零基础入门!转载他人的!
安装Python 前往 官网下载 对应平台对应工具.另外Python2.7版本和3.3版本并不兼容,所以开发时请注意使用Python的版本. 作为Mac OS X使用者,其实更推荐 PyCharm I ...
- 2018-2019-20175205 实验三敏捷开发与XP实践《Java开发环境的熟悉》实验报告
2018-2019-20175205 实验三敏捷开发与XP实践<Java开发环境的熟悉>实验报告 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)>&l ...
- Java EE开发技术课程第七周(json)
JSON: https://baike.baidu.com/item/JSON/2462549?fr=aladdin JSON指JavaScript对象表示法(JavaScript Object No ...
- linux下wrk的安装
wrk是linux下开源的性能测试工具,并且只能在linux下运行,下面介绍下安装教程(以ubantu18.04环境为例): 1.预先安装git,如:apt install git 2.从git上拉取 ...
- nginx + keepalived 主从模式
转自:https://www.cnblogs.com/kevingrace/p/6138185.html 负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可 ...
- Echarts 柱状图配置详解
1.基本柱状图 // 指定图表的配置项和数据 var option = { // ---- 标题 ----- title: { text: '主标题', textStyle: { color: 're ...
- js--深拷贝与浅拷贝
对象:只针对于Object和Array这样的引用数据类型 说明:浅拷贝只复制指向某个对象的指针,而不是复制对象的本身,新旧对象还是共享一块内存.但深拷贝会另外创造一个一模一样的对象,新的对象跟原对象不 ...