Javascript 如何使用node.js crypto计算blob的sha1哈希
在我的node.js应用程序中,我想上传一个文件并计算sha1 我尝试了以下方法:Javascript 如何使用node.js crypto计算blob的sha1哈希,javascript,node.js,hash,sha1,Javascript,Node.js,Hash,Sha1,在我的node.js应用程序中,我想上传一个文件并计算sha1 我尝试了以下方法: export function calculateHash(file, type){ const reader = new FileReader(); var hash = crypto.createHash('sha1'); hash.setEncoding('hex'); const testfile = reader.readAsDataURL(file); hash.write(tes
export function calculateHash(file, type){
const reader = new FileReader();
var hash = crypto.createHash('sha1');
hash.setEncoding('hex');
const testfile = reader.readAsDataURL(file);
hash.write(testfile);
hash.end();
var sha1sum = hash.read();
console.log(sha1sum);
// fd.on((end) => {
// hash.end();
// const test = hash.read();
// });
}
该文件是通过在我的网站上使用文件上载按钮选择的文件
如何计算sha1散列?如果将中的内容作为块读取,则会使其变得比需要的更难。我们这样做:
const fs = require('fs');
export function calculateHash(file, type){
const testfile = fs.readFileSync(file);
var sha1sum = crypto.createHash('sha1').update(testFile).digest("hex");
console.log(sha1sum);
}
CryptoJS主要是一个客户端库,不应该与node.js的加密模块混淆。哪一个适合你?你在这里展示的代码有什么问题?它是否已经工作了?解决方案生成了一个错误。一旦
testfile
和testfile