在 postgres 中,我使用此函数将 md5 哈希转换为 bigint:
SELECT ('x'||substr(md5('text'),1,16))::bit(64)::bigint;
此查询的结果将为 2067805253194386918
。
如何在 NodeJS/Javascript 中执行此操作?
谢谢!
最佳答案
使用crypto
包(包含在NodeJs中)和新的BigInt
类型。
const crypto = require('crypto');
const md5 = crypto.createHash('md5').update('text').digest('hex');
const bigInt = BigInt(`0x${md5.substring(0, 16)}`);
关于javascript - 在nodejs中将md5哈希转换为bigint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65023122/