目前我用nodejs编写了这段代码。在
const sha256 = require('js-sha256').sha256;
var stringl = "8d12a197cb00d4747a1fe03395095ce2a5cc68198f3470a7388c05ee4e7af3d01d8c722b0ff5237400000000000000000000000000000000000000000000000000000000000000b40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003600000000000000000000000000000000000000000000000000000000004c4b40000000000000000000000000000000000000000000000000000000000001e240"
console.log(sha256(new Buffer(stringl, 'hex')));
它回来了
^{pr2}$我想把代码从nodejs转换成python(3.5)。在
我以为我可以用这个代码来做。在
import hashlib
string21 = "8d12a197cb00d4747a1fe03395095ce2a5cc68198f3470a7388c05ee4e7af3d01d8c722b0ff5237400000000000000000000000000000000000000000000000000000000000000b40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003600000000000000000000000000000000000000000000000000000000004c4b40000000000000000000000000000000000000000000000000000000000001e240"
print(hashlib.sha256(str(int(string21,16)).encode('utf-8')).hexdigest())
但这又回来了
346c61765546d4ff12fdbea997f40bdb5216b8df2b5402a6b45893df723132f6
有什么想法吗?在
Buffer
返回一个字节数组(range(0, 256)
中的整数),因此您需要在Python中执行相同的操作:bytearray.fromhex
正是它所说的:从十六进制表示创建一个bytearray
。在编辑:这里不需要
encode
任何东西,因为bytearray
s已经表示字节了。在相关问题 更多 >
编程相关推荐