先看图(我这里是H5运行的,到手机上直接就调用键盘了) (c+v改接口即可运行)
这里第二次密码错误会有一个判断,提示密码错误重新输入
上代码(这是第一页的代码)(注意看有一个引入的文件 uuid 在下面有写到)
<template>
<view class="">
<view class="paymentBox">
<u-cell-item v-if="payPassword == ''" title="设置6位数字支付密码" @click="goPaymentBox1()"></u-cell-item>
<u-cell-item v-else title="忘记6位数字支付密码" @click="goPaymentBox()"></u-cell-item>
</view>
<p class="paymentBox-p">支付密码是为了提高用户账号的安全性而设置的。一旦设置了安全密码,在涉及支付的关键环节会提示输入,使您的账户更有保障。</p>
</view>
</template>
<script>
// import {yuee,redd,searchIdentity} from "@/api/minefenx.js";
import { selectPassword } from "@/api/store.js";
import storage from "@/utils/storage.js";
import uuid from "@/utils/uuid.modified.js";
import {
sendMobilss
} from "@/api/login";
export default {
data() {
return {
phone: "",
uuid: uuid.v1(),
danguuid: '',
payPassword:""//用户密码
}
},
onShow() {
this.getList()
},
methods: {
getList(){
let data={
memberId:storage.getUserInfo().id
}
selectPassword(data).then(res=>{
console.log(res,'res')
this.payPassword = res.data
})
},
navigateTo(url) {
uni.navigateTo({
url: url,
});
},
goPaymentBox() {
this.phone=storage.getUserInfo().mobile || "";
console.log("this.phonid",this.phonid)
var phons = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
if (!phons.test(this.phone)) {
uni.showToast({
title: '手机号格式不正确',
icon: "none"
})
this.phone = ''
return
};
this.danguuid = uuid.v1()
sendMobilss(this.phone,this.danguuid).then(res=>{
console.log(res,'res')
if(res.data.success){
uni.navigateTo({
url:`路径?uuid=${this.danguuid}`,
});
}
})
},
goPaymentBox1() {
this.phone=storage.getUserInfo().mobile || "";
console.log("this.phonid",this.phonid)
var phons = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
if (!phons.test(this.phone)) {
uni.showToast({
title: '手机号格式不正确',
icon: "none"
})
this.phone = ''
return
};
this.danguuid = uuid.v1()
// uni.setStorageSync(this.danguuid,res);
sendMobilss(this.phone,this.danguuid).then(res=>{
console.log(res,'res')
if(res.data.success){
uni.navigateTo({
url:`路径?uuid=${this.danguuid}`,
});
}
})
},
}
}
</script>
<style>
.paymentBox {
background: #fff;
margin-top: 2%;
}
.paymentBox-p {
padding-top: 20px;
width: 95%;
padding-left: 2%;
text-align: justify;
font-size: 12px;
color: gray;
line-height: 20px;
}
</style>
-------------------------------这个uuid文件我也是在网上借鉴的哈哈哈哈哈 下面都有用到---
// uuid.js
//
// Copyright (c) 2010-2012 Robert Kieffer
// MIT License - http://opensource.org/licenses/mit-license.php
/*global window, require, define */
(function(_window) {
'use strict';
// Unique ID creation requires a high quality random # generator. We feature
// detect to determine the best RNG source, normalizing to a function that
// returns 128-bits of randomness, since that's what's usually required
var _rng, _mathRNG, _nodeRNG, _whatwgRNG, _previousRoot;
function setupBrowser() {
// Allow for MSIE11 msCrypto
//var _crypto = _window.crypto || _window.msCrypto;
var crypto = {}
var _crypto = crypto || _window.crypto || _window.msCrypto;
if (!_rng && _crypto && _crypto.getRandomValues) {
// WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
//
// Moderately fast, high quality
try {
var _rnds8 = new Uint8Array(16);
_whatwgRNG = _rng = function whatwgRNG() {
_crypto.getRandomValues(_rnds8);
return _rnds8;
};
_rng();
} catch (e) {}
}
if (!_rng) {
// Math.random()-based (RNG)
//
// If all else fails, use Math.random(). It's fast, but is of unspecified
// quality.
var _rnds = new Array(16);
_mathRNG = _rng = function() {
for (var i = 0, r; i < 16; i++) {
if ((i & 0x03) === 0) { r = Math.random() * 0x100000000; }
_rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
}
return _rnds;
};
if ('undefined' !== typeof console && console.warn) {
// console.warn("[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()");
}
}
}
setupBrowser();
// Buffer class to use
var BufferClass = ('function' === typeof Buffer) ? Buffer : Array;
// Maps for number <-> hex string conversion
var _byteToHex = [];
var _hexToByte = {};
for (var i = 0; i < 256; i++) {
_byteToHex[i] = (i + 0x100).toString(16).substr(1);
_hexToByte[_byteToHex[i]] = i;
}
// **`parse()` - Parse a UUID into it's component bytes**
function parse(s, buf, offset) {
var i = (buf && offset) || 0,
ii = 0;
buf = buf || [];
s.toLowerCase().replace(/[0-9a-f]{2}/g, function(oct) {
if (ii < 16) { // Don't overflow!
buf[i + ii++] = _hexToByte[oct];
}
});
// Zero out remaining bytes if string was short
while (ii < 16) {
buf[i + ii++] = 0;
}
return buf;
}
// **`unparse()` - Convert UUID byte array (ala parse()) into a string**
function unparse(buf, offset) {
var i = offset || 0,
bth = _byteToHex;
return bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]];
}
// **`v1()` - Generate time-based UUID**
//
// Inspired by https://github.com/LiosK/UUID.js
// and http://docs.python.org/library/uuid.html
// random #'s we need to init node and clockseq
var _seedBytes = _rng();
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
var _nodeId = [
_seedBytes[0] | 0x01,
_seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]
];
// Per 4.2.2, randomize (14 bit) clockseq
var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;
// Previous uuid creation time
var _lastMSecs = 0,
_lastNSecs = 0;
// See https://github.com/broofa/node-uuid for API details
function v1(options, buf, offset) {
var i = buf && offset || 0;
var b = buf || [];
options = options || {};
var clockseq = (options.clockseq != null) ? options.clockseq : _clockseq;
// UUID timestamps are 100 nano-second units since the Gregorian epoch,
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
// time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
var msecs = (options.msecs != null) ? options.msecs : new Date().getTime();
// Per 4.2.1.2, use count of uuid's generated during the current clock
// cycle to simulate higher resolution clock
var nsecs = (options.nsecs != null) ? options.nsecs : _lastNSecs + 1;
// Time since last uuid creation (in msecs)
var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs) / 10000;
// Per 4.2.1.2, Bump clockseq on clock regression
if (dt < 0 && options.clockseq == null) {
clockseq = clockseq + 1 & 0x3fff;
}
// Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
// time interval
if ((dt < 0 || msecs > _lastMSecs) && options.nsecs == null) {
nsecs = 0;
}
// Per 4.2.1.2 Throw error if too many uuids are requested
if (nsecs >= 10000) {
throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
}
_lastMSecs = msecs;
_lastNSecs = nsecs;
_clockseq = clockseq;
// Per 4.1.4 - Convert from unix epoch to Gregorian epoch
msecs += 12219292800000;
// `time_low`
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
b[i++] = tl >>> 24 & 0xff;
b[i++] = tl >>> 16 & 0xff;
b[i++] = tl >>> 8 & 0xff;
b[i++] = tl & 0xff;
// `time_mid`
var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
b[i++] = tmh >>> 8 & 0xff;
b[i++] = tmh & 0xff;
// `time_high_and_version`
b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
b[i++] = tmh >>> 16 & 0xff;
// `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
b[i++] = clockseq >>> 8 | 0x80;
// `clock_seq_low`
b[i++] = clockseq & 0xff;
// `node`
var node = options.node || _nodeId;
for (var n = 0; n < 6; n++) {
b[i + n] = node[n];
}
return buf ? buf : unparse(b);
}
// **`v4()` - Generate random UUID**
// See https://github.com/broofa/node-uuid for API details
function v4(options, buf, offset) {
// Deprecated - 'format' argument, as supported in v1.2
var i = buf && offset || 0;
if (typeof(options) === 'string') {
buf = (options === 'binary') ? new BufferClass(16) : null;
options = null;
}
options = options || {};
var rnds = options.random || (options.rng || _rng)();
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
rnds[6] = (rnds[6] & 0x0f) | 0x40;
rnds[8] = (rnds[8] & 0x3f) | 0x80;
// Copy bytes to buffer, if provided
if (buf) {
for (var ii = 0; ii < 16; ii++) {
buf[i + ii] = rnds[ii];
}
}
return buf || unparse(rnds);
}
// Export public API
var uuid = v4;
uuid.v1 = v1;
uuid.v4 = v4;
uuid.parse = parse;
uuid.unparse = unparse;
uuid.BufferClass = BufferClass;
uuid._rng = _rng;
uuid._mathRNG = _mathRNG;
uuid._nodeRNG = _nodeRNG;
uuid._whatwgRNG = _whatwgRNG;
if (('undefined' !== typeof module) && module.exports) {
// Publish as node.js module
module.exports = uuid;
} else if (typeof define === 'function' && define.amd) {
// Publish as AMD module
define(function() { return uuid; });
} else {
// Publish as global (in browsers)
_previousRoot = _window.uuid;
// **`noConflict()` - (browser only) to reset global 'uuid' var**
uuid.noConflict = function() {
_window.uuid = _previousRoot;
return uuid;
};
_window.uuid = uuid;
}
})('undefined' !== typeof window ? window : null);
第二张图片的代码 验证验证码输入是否正确
<template>
<view class="forgetPassword">
<div class="forgetPasswordBox">
<h2>输入短信验证码</h2>
<p>
<span style="color: gray;">验证码已发送至</span>
<span>+86 {{phonenum}}</span>
</p>
<u-message-input :focus="true" :maxlength='6' mode="box" @change="valChange" @backspace="backspace"
v-model="show"></u-message-input>
<p style="text-align: right;padding-right:7%;padding-top:3%;color:gray">
<span></span>
</p>
</div>
</view>
</template>
<script>
import storage from "@/utils/storage.js";
import uuid from "@/utils/uuid.modified.js";
import {
PaymentPost
} from "@/api/login";
export default {
data() {
return {
value: '', //密码
show: '',
phone: "",//手机号
danguuid: '',
phonenum:""//加密的手机号
}
},
onLoad(e) {
this.danguuid = e.uuid
console.log(a,'a')
this.phone = storage.getUserInfo().mobile
let a = storage.getUserInfo().mobile
console.log(a,'aaaa')
for(let i = 0 ; i < a.length ; i++){
let str1 = a.slice(0,3)
let str2 = a.slice(7,11)
let str3 = str1+'****'+str2
a = str3
}
console.log(a,'a')
this.phonenum =a
},
methods: {
// 按键被点击(点击退格键不会触发此事件)
valChange(val) {
// 将每次按键的值拼接到value变量中,注意+=写法
this.value = val;
if (val.length == 6) {
var phons = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
if (!phons.test(this.phone)) {
uni.showToast({
title: '手机号格式不正确',
icon: "none"
})
this.phone = ''
return
};
if (this.value == '' || this.value == null) {
uni.showToast({
title: '请输入验证码',
icon: "none"
})
}
console.log(this.danguuid, 'this.danguuid')
PaymentPost({
mobile: this.phone,
code: this.value,
uuid: this.danguuid
}).then(res => {
console.log(res,'res66666')
if (res.statusCode == 200) {
uni.navigateTo({
url: `路径`
});
}
})
}
// uni.navigateTo({
// url: `路径`,
// });
},
// 退格键被点击
backspace() {
// 删除value的最后一个字符
if (this.value.length) this.value = this.value.substr(0, this.value.length - 1);
}
}
}
</script>
<style>
body,
html {
height: 100%;
}
.forgetPassword {
height: 100%;
background-color: #fff;
}
.forgetPasswordBox {
width: 90%;
padding-left: 5%;
}
.forgetPasswordBox h2 {
padding-top: 10%;
padding-bottom: 5%;
}
.forgetPasswordBox p {
padding-bottom: 5%;
}
</style>
第三张图 输入密码
<template>
<div class="setPasswordBox">
<P class="setPasswordBox-p">请输入6位数字支付密码</P>
<u-message-input :focus="true" :maxlength='6' mode="box" @change="valChange" @backspace="backspace"
v-model="show"></u-message-input>
</div>
</template>
<script>
export default {
data() {
return {
value: '', //密码
show: ''
}
},
methods: {
// 按键被点击(点击退格键不会触发此事件)
valChange(val) {
console.log(val, 'val111111111')
// 将每次按键的值拼接到value变量中,注意+=写法
this.value = val;
if (val.length == 6) {
uni.navigateTo({
url: `路径?password=${this.value}`,
});
this.value = ''
}
// console.log(this.value);
},
// 退格键被点击
backspace() {
// 删除value的最后一个字符
if (this.value.length) this.value = this.value.substr(0, this.value.length - 1);
// console.log(this.value);
}
}
}
</script>
<style>
body,
html {
height: 100%;
}
.setPasswordBox {
background: #fff;
height: 100%;
margin-top: 2%;
}
.setPasswordBox-p {
padding-left: 35%;
color: gray;
line-height: 100px;
}
</style>
第四张图再次输入密码 这里会有一个判断 是否和第一次输入的密码一样 同时对密码进行加密处理传给后端 这也是需要引入一个文件的,用来对密码进行加密处理
<template>
<div class="setPasswordBox">
<P class="forgetPassword3-p">请再次输入新6位数字支付密码</P>
<u-message-input :focus="true" :maxlength='6' mode="box" @change="valChange" @backspace="backspace"
v-model="show"></u-message-input>
<u-top-tips ref="uTips"></u-top-tips>
<u-toast ref="uToast" />
</div>
</template>
<script>
import { md5 } from '@/utils/md5.js'
import storage from "@/utils/storage.js";
import {
PasswordPost
} from "@/api/login";
export default {
data() {
return {
user: "",
value: '', //密码
show: '',
password: "" //第一次的密码
}
},
onLoad(e) {
console.log(e, 'e')
this.password = e.password;
this.user = storage.getUserInfo();
console.log(this.user, 'this.user');
},
methods: {
// 按键被点击(点击退格键不会触发此事件)
valChange(val) {
// 将每次按键的值拼接到value变量中,注意+=写法
this.value = val;
if (val.length == 6) {
if (val == this.password) {
let x = md5(this.value)
PasswordPost({
shopUserId:this.user.shopSysUserId,
memberId: this.user.id,
payPassword:x
}).then(res => {
console.log(res, 'res')
if (res.statusCode == 200) {
// this.$refs.uToast.show({
// title: '设置成功',
// type: 'success',
// url: '路径'
// })
uni.showToast({
title: '设置成功',
duration: 2000,
icon: 'none'
});
uni.switchTab({
url: '路径'
});
}
})
} else {
this.$refs.uTips.show({
title: '两次密码不一致',
type: 'error',
duration: '2300'
})
}
}
console.log(this.value);
},
// 退格键被点击
backspace() {
// 删除value的最后一个字符
if (this.value.length) this.value = this.value.substr(0, this.value.length - 1);
// console.log(this.value);
}
}
}
</script>
<style>
body,
html {
height: 100%;
}
.setPasswordBox {
background: #fff;
height: 100%;
margin-top: 2%;
}
.forgetPassword3-p {
padding-left: 25%;
color: gray;
line-height: 100px;
}
</style>
----------------------加密处理密码的代码 图中的 md5-----------------------------
/*
* 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 hh(a, b, c, d, x, s, t) {
return cmn(b ^ c ^ d, a, b, x, s, t)
}
function ii(a, b, c, d, x, s, t) {
return cmn(c ^ (b | (~d)), a, b, x, s, t)
}
/*
* Calculate the MD5 of an array of little-endian words, producing an array
* of little-endian words.
*/
function coreMD5(x) {
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 = ff(a, b, c, d, x[i + 0], 7, -680876936)
d = ff(d, a, b, c, x[i + 1], 12, -389564586)
c = ff(c, d, a, b, x[i + 2], 17, 606105819)
b = ff(b, c, d, a, x[i + 3], 22, -1044525330)
a = ff(a, b, c, d, x[i + 4], 7, -176418897)
d = ff(d, a, b, c, x[i + 5], 12, 1200080426)
c = ff(c, d, a, b, x[i + 6], 17, -1473231341)
b = ff(b, c, d, a, x[i + 7], 22, -45705983)
a = ff(a, b, c, d, x[i + 8], 7, 1770035416)
d = ff(d, a, b, c, x[i + 9], 12, -1958414417)
c = ff(c, d, a, b, x[i + 10], 17, -42063)
b = ff(b, c, d, a, x[i + 11], 22, -1990404162)
a = ff(a, b, c, d, x[i + 12], 7, 1804603682)
d = ff(d, a, b, c, x[i + 13], 12, -40341101)
c = ff(c, d, a, b, x[i + 14], 17, -1502002290)
b = ff(b, c, d, a, x[i + 15], 22, 1236535329)
a = gg(a, b, c, d, x[i + 1], 5, -165796510)
d = gg(d, a, b, c, x[i + 6], 9, -1069501632)
c = gg(c, d, a, b, x[i + 11], 14, 643717713)
b = gg(b, c, d, a, x[i + 0], 20, -373897302)
a = gg(a, b, c, d, x[i + 5], 5, -701558691)
d = gg(d, a, b, c, x[i + 10], 9, 38016083)
c = gg(c, d, a, b, x[i + 15], 14, -660478335)
b = gg(b, c, d, a, x[i + 4], 20, -405537848)
a = gg(a, b, c, d, x[i + 9], 5, 568446438)
d = gg(d, a, b, c, x[i + 14], 9, -1019803690)
c = gg(c, d, a, b, x[i + 3], 14, -187363961)
b = gg(b, c, d, a, x[i + 8], 20, 1163531501)
a = gg(a, b, c, d, x[i + 13], 5, -1444681467)
d = gg(d, a, b, c, x[i + 2], 9, -51403784)
c = gg(c, d, a, b, x[i + 7], 14, 1735328473)
b = gg(b, c, d, a, x[i + 12], 20, -1926607734)
a = hh(a, b, c, d, x[i + 5], 4, -378558)
d = hh(d, a, b, c, x[i + 8], 11, -2022574463)
c = hh(c, d, a, b, x[i + 11], 16, 1839030562)
b = hh(b, c, d, a, x[i + 14], 23, -35309556)
a = hh(a, b, c, d, x[i + 1], 4, -1530992060)
d = hh(d, a, b, c, x[i + 4], 11, 1272893353)
c = hh(c, d, a, b, x[i + 7], 16, -155497632)
b = hh(b, c, d, a, x[i + 10], 23, -1094730640)
a = hh(a, b, c, d, x[i + 13], 4, 681279174)
d = hh(d, a, b, c, x[i + 0], 11, -358537222)
c = hh(c, d, a, b, x[i + 3], 16, -722521979)
b = hh(b, c, d, a, x[i + 6], 23, 76029189)
a = hh(a, b, c, d, x[i + 9], 4, -640364487)
d = hh(d, a, b, c, x[i + 12], 11, -421815835)
c = hh(c, d, a, b, x[i + 15], 16, 530742520)
b = hh(b, c, d, a, x[i + 2], 23, -995338651)
a = ii(a, b, c, d, x[i + 0], 6, -198630844)
d = ii(d, a, b, c, x[i + 7], 10, 1126891415)
c = ii(c, d, a, b, x[i + 14], 15, -1416354905)
b = ii(b, c, d, a, x[i + 5], 21, -57434055)
a = ii(a, b, c, d, x[i + 12], 6, 1700485571)
d = ii(d, a, b, c, x[i + 3], 10, -1894986606)
c = ii(c, d, a, b, x[i + 10], 15, -1051523)
b = ii(b, c, d, a, x[i + 1], 21, -2054922799)
a = ii(a, b, c, d, x[i + 8], 6, 1873313359)
d = ii(d, a, b, c, x[i + 15], 10, -30611744)
c = ii(c, d, a, b, x[i + 6], 15, -1560198380)
b = ii(b, c, d, a, x[i + 13], 21, 1309151649)
a = ii(a, b, c, d, x[i + 4], 6, -145523070)
d = ii(d, a, b, c, x[i + 11], 10, -1120210379)
c = ii(c, d, a, b, x[i + 2], 15, 718787259)
b = 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 [a, b, c, d]
}
/*
* Convert an array of little-endian words to a hex string.
*/
function binl2hex(binarray) {
var hex_tab = "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 base64 encoded string.
*/
function binl2b64(binarray) {
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
var str = ""
for (var i = 0; i < binarray.length * 32; i += 6) {
str += tab.charAt(((binarray[i >> 5] << (i % 32)) & 0x3F) |
((binarray[i >> 5 + 1] >> (32 - i % 32)) & 0x3F))
}
return str
}
/*
* Convert an 8-bit character string to a sequence of 16-word blocks, stored
* as an array, and append appropriate padding for MD4/5 calculation.
* If any of the characters are >255, the high byte is silently ignored.
*/
function str2binl(str) {
var nblk = ((str.length + 8) >> 6) + 1 // number of 16-word blocks
var blks = new Array(nblk * 16)
for (var i = 0; i < nblk * 16; i++) blks[i] = 0
for (var i = 0; i < str.length; i++)
blks[i >> 2] |= (str.charCodeAt(i) & 0xFF) << ((i % 4) * 8)
blks[i >> 2] |= 0x80 << ((i % 4) * 8)
blks[nblk * 16 - 2] = str.length * 8
return blks
}
/*
* Convert a wide-character string to a sequence of 16-word blocks, stored as
* an array, and append appropriate padding for MD4/5 calculation.
*/
function strw2binl(str) {
var nblk = ((str.length + 4) >> 5) + 1 // number of 16-word blocks
var blks = new Array(nblk * 16)
for (var i = 0; i < nblk * 16; i++) blks[i] = 0
for (var i = 0; i < str.length; i++)
blks[i >> 1] |= str.charCodeAt(i) << ((i % 2) * 16)
blks[i >> 1] |= 0x80 << ((i % 2) * 16)
blks[nblk * 16 - 2] = str.length * 16
return blks
}
/*
* External interface
*/
function hexMD5(str) {
return binl2hex(coreMD5(str2binl(str)))
}
function hexMD5w(str) {
return binl2hex(coreMD5(strw2binl(str)))
}
function b64MD5(str) {
return binl2b64(coreMD5(str2binl(str)))
}
function b64MD5w(str) {
return binl2b64(coreMD5(strw2binl(str)))
}
/* Backward compatibility */
function calcMD5(str) {
return binl2hex(coreMD5(str2binl(str)))
}
module.exports = {
md5: hexMD5
}