概述摘要用于校验数据完整性。本文提供整文件与分块的 SHA-256 计算示例。整文件摘要async function hashFile(file) { const buf = await file.arrayBuffer(); const d = await crypto.subtle.digest('SHA-256', buf); return Array.from(new Uint8Array(d)).map(x => x.toString(16).padStart(2,'0')).join(''); } 分块摘要序列async function hashChunks(file, size = 1024 * 1024) { let o = 0; const out = []; while (o < file.size) { const b = file.slice(o, o + size); const ab = await b.arrayBuffer(); const d = await crypto.subtle.digest('SHA-256', ab); const hex = Array.from(new Uint8Array(d)).map(x => x.toString(16).padStart(2,'0')).join(''); out.push(hex); o += size; } return out; }

发表评论 取消回复