const crypto = require('crypto');
function md5(str, boolean) {
var md5 = crypto.createHash('md5');
var strBuffer = Buffer.isBuffer(str) ? str : new Buffer(str);
md5.update(strBuffer);
//如果boolean为true,则返回16字符二进制数,否则返回32位16进制数
if (boolean)
return md5.digest('binary');
return md5.digest('hex');
}
//调用方法和php基本一致
const str = new Buffer(md5('123456', true), 'binary').toString('base64');
//输出可得4QrcOUm6Wau+VuBX8g+IPg==
console.log(str);
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这个是
BASE64的MD5,github上面也有很多实现。举个栗子:
gist.github.com/nyxtom/4726954
md5.js
使用方法:
在你的node项目的node_modules里找到你需要的js,直接<script>方法引到你的页面,就可以用了。
像这样找到这个js