<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-build-a-browser-based-file-integrity-checker-with-javascript-w3qjqlklp" -->

---
title: How to Build a Browser-Based File Integrity Checker with...
description: A step-by-step tutorial builds a browser-based file integrity checker using the Web Crypto API to compute a SHA-256 hash of a locally selected file, compare it...
canonical: https://daily.dev/posts/how-to-build-a-browser-based-file-integrity-checker-with-javascript-w3qjqlklp
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Build a Browser-Based File Integrity Checker with JavaScript | daily.dev
og:description: A step-by-step tutorial builds a browser-based file integrity checker using the Web Crypto API to compute a SHA-256 hash of a locally selected file, compare it...
og:url: https://daily.dev/posts/how-to-build-a-browser-based-file-integrity-checker-with-javascript-w3qjqlklp
og:image: https://api.daily.dev/og/posts/w3QJQLKlp.png
og:image:alt: How to Build a Browser-Based File Integrity Checker with JavaScript
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Build a Browser-Based File Integrity Checker with JavaScript

**[SitePoint](https://daily.dev/sources/sitepoint)** · 6 min read · 1 upvotes · 0 comments

## Summary

A step-by-step tutorial builds a browser-based file integrity checker using the Web Crypto API to compute a SHA-256 hash of a locally selected file, compare it against a trusted hash, and let the user copy the result without uploading the file to a server. It covers the HTML interface, hashing logic with crypto.subtle.digest(), hash normalization and validation, handling large files with a size limit, and using the Clipboard API for copying results. It closes with security caveats: hash matches are only meaningful if the trusted hash comes from a source the attacker cannot also tamper with, and hash comparison is not the same as digital-signature verification.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.sitepoint.com/how-to-build-a-browser-based-file-integrity-checker-with-javascript>

## Questions this post answers

### How do I calculate a SHA-256 hash of a file in the browser using JavaScript?

Read the file as an ArrayBuffer with file.arrayBuffer(), then pass it to crypto.subtle.digest('SHA-256', fileBuffer), which returns a promise resolving to another ArrayBuffer. Convert that buffer to a Uint8Array, map each byte to a two-character hex string, and join them to produce the 64-character SHA-256 hash string, entirely client-side with no upload needed.

_daily.dev surfaces practical Web Crypto API walkthroughs for developers building client-side hashing features._

### Why would a matching SHA-256 hash comparison still fail to prove a file is authentic?

A matching hash only confirms the file matches the version the trusted hash was generated from, not who created or signed it. If an attacker can replace both the downloadable file and its displayed hash on the same compromised system, the comparison still passes, so trusted hashes need distribution through a separate protected channel, authenticated API, or signed manifest.

_Developers weighing hash checks versus digital signatures can track these security trade-offs on daily.dev._

### What is the file size limitation of the Web Crypto API's digest() method in the browser?

crypto.subtle.digest() requires the entire file to be loaded into memory via arrayBuffer() rather than streaming input, which works fine for ordinary documents but can cause performance problems with multi-gigabyte files. A practical mitigation is enforcing a size limit, such as rejecting files over 100 MB, or offloading heavy processing to a Web Worker to avoid blocking the page.

_daily.dev helps developers stay on top of browser API limitations before they hit production._

## Similar posts on daily.dev

- [Verifiable Bookmarklets](https://daily.dev/posts/verifiable-bookmarklets-qwfvcnuy3) · ITNEXT · 1 upvotes · 0 comments
- [Trustworthy JavaScript for the Open Web](https://daily.dev/posts/trustworthy-javascript-for-the-open-web-7odqn9ra4) · Mozilla Hacks · 0 upvotes · 0 comments
- [When Reading the Source Code Is the Real Hack: A Web Challenge Story \| v1t CTF](https://daily.dev/posts/when-reading-the-source-code-is-the-real-hack-a-web-challenge-story-v1t-ctf-1ijq4fc2k) · InfoSec Write-ups · 1 upvotes · 0 comments
- [How to Build a Bulk Image Compressor Tool with HTML, CSS, and JavaScript](https://daily.dev/posts/how-to-build-a-bulk-image-compressor-tool-with-html-css-and-javascript-rthqxmxie) · freeCodeCamp · 6 upvotes · 0 comments
- [What Every Android Engineer Needs to Know About SHA-1, SHA-256, and Beyond](https://daily.dev/posts/what-every-android-engineer-needs-to-know-about-sha-1-sha-256-and-beyond-g6asxoyyz) · ProAndroidDev · 1 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/how-to-build-a-browser-based-file-integrity-checker-with-javascript-w3qjqlklp)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Build a Browser-Based File Integrity Checker with JavaScript","url":"https://daily.dev/posts/how-to-build-a-browser-based-file-integrity-checker-with-javascript-w3qjqlklp","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-build-a-browser-based-file-integrity-checker-with-javascript-w3qjqlklp"},"datePublished":"2026-09-18T15:26:39.698Z","dateModified":"2026-09-18T15:27:02.731Z","description":"A step-by-step tutorial builds a browser-based file integrity checker using the Web Crypto API to compute a SHA-256 hash of a locally selected file, compare it...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8e20e9181658acdf112f7740738e3719?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8e20e9181658acdf112f7740738e3719?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"SitePoint","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SitePoint","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/sitepoint","url":"https://daily.dev/sources/sitepoint"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-build-a-browser-based-file-integrity-checker-with-javascript-w3qjqlklp","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SitePoint","item":"https://daily.dev/sources/sitepoint"},{"@type":"ListItem","position":3,"name":"How to Build a Browser-Based File Integrity Checker with JavaScript"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-build-a-browser-based-file-integrity-checker-with-javascript-w3qjqlklp#faq","mainEntity":[{"@type":"Question","name":"How do I calculate a SHA-256 hash of a file in the browser using JavaScript?","acceptedAnswer":{"@type":"Answer","text":"Read the file as an ArrayBuffer with file.arrayBuffer(), then pass it to crypto.subtle.digest('SHA-256', fileBuffer), which returns a promise resolving to another ArrayBuffer. Convert that buffer to a Uint8Array, map each byte to a two-character hex string, and join them to produce the 64-character SHA-256 hash string, entirely client-side with no upload needed. daily.dev surfaces practical Web Crypto API walkthroughs for developers building client-side hashing features."}},{"@type":"Question","name":"Why would a matching SHA-256 hash comparison still fail to prove a file is authentic?","acceptedAnswer":{"@type":"Answer","text":"A matching hash only confirms the file matches the version the trusted hash was generated from, not who created or signed it. If an attacker can replace both the downloadable file and its displayed hash on the same compromised system, the comparison still passes, so trusted hashes need distribution through a separate protected channel, authenticated API, or signed manifest. Developers weighing hash checks versus digital signatures can track these security trade-offs on daily.dev."}},{"@type":"Question","name":"What is the file size limitation of the Web Crypto API's digest() method in the browser?","acceptedAnswer":{"@type":"Answer","text":"crypto.subtle.digest() requires the entire file to be loaded into memory via arrayBuffer() rather than streaming input, which works fine for ordinary documents but can cause performance problems with multi-gigabyte files. A practical mitigation is enforcing a size limit, such as rejecting files over 100 MB, or offloading heavy processing to a Web Worker to avoid blocking the page. daily.dev helps developers stay on top of browser API limitations before they hit production."}}]}
```

