【发布时间】:2020-05-04 07:28:27
【问题描述】:
我目前在 Nodejs 中使用 PHP-PACK
但不幸的是,它在 windows 上不起作用
那么有谁知道 js 代码具有与
相同的功能pack('H*', md5('password')
我尝试了此参考中的此代码,但无助于解决问题
String.prototype.packHex = function () {
var source = this.length % 2 ? this + '0' : this
var result = ''
for (var i = 0; i < source.length; i = i + 3) {
result += String.fromCharCode(parseInt(source.substr(i, 2), 16))
}
return result
}
console.log('Pack-hex: --->', Buffer.from(md5('password').packHex()))
console.log('php-pack: --->', Buffer.from(pack('H*', md5('password'))))
结果:
Pack-hex: ---> X8OcO8KqZWHCg33CuCzCmQ==
php-pack: ---> X03MO1qnZdYdgyfeuILPmQ==
感谢您的帮助
【问题讨论】:
标签: javascript node.js hash