Last active
May 14, 2026 11:43
-
-
Save fancellu/f4bbb79c30109f12496d69fcbbbda484 to your computer and use it in GitHub Desktop.
RSA Signature verifier (SHA-256)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <body style="font-family:sans-serif; padding:30px; background:#1e1e1e; color:#eee;"> | |
| <h2>RSA Binary Verifier (No Size Limit)</h2> | |
| <label>1. Public Key (PEM):</label><br> | |
| <textarea id="p" style="width:100%; height:120px; background:#333; color:#fff; border:1px solid #555;"></textarea><br><br> | |
| <label>2. Signature (Base64):</label><br> | |
| <input id="s" type="text" style="width:100%; background:#333; color:#fff; border:1px solid #555;"><br><br> | |
| <label>3. Binary Payload:</label><br> | |
| <input type="file" id="f"> | |
| <button onclick="v()" style="padding:10px 20px; background:#007acc; color:white; border:none; cursor:pointer;">Verify Signature</button> | |
| <h1 id="r" style="margin-top:20px;"></h1> | |
| <script> | |
| async function v() { | |
| const r = document.getElementById('r'); | |
| try { | |
| const pubText = document.getElementById('p').value; | |
| const sigB64 = document.getElementById('s').value; | |
| const file = document.getElementById('f').files[0]; | |
| if (!file) throw new Error("Select a file"); | |
| // Clean PEM and decode Signature | |
| const pem = pubText.replace(/-----.*?-----/g, "").replace(/\s+/g, ""); | |
| const keyBuf = Uint8Array.from(atob(pem), c => c.charCodeAt(0)); | |
| const sigBuf = Uint8Array.from(atob(sigB64), c => c.charCodeAt(0)); | |
| // Read file as ArrayBuffer (handles large binary blobs) | |
| const dataBuf = await file.arrayBuffer(); | |
| // Import Key (RSASSA-PKCS1-v1_5 matches your Node.js crypto code) | |
| const key = await crypto.subtle.importKey( | |
| "spki", keyBuf, {name: "RSASSA-PKCS1-v1_5", hash: "SHA-256"}, false, ["verify"] | |
| ); | |
| const valid = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key, sigBuf, dataBuf); | |
| r.innerText = valid ? "✅ VALID" : "❌ INVALID"; | |
| r.style.color = valid ? "#4caf50" : "#f44336"; | |
| } catch (e) { | |
| r.innerText = "Error: " + e.message; | |
| r.style.color = "orange"; | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment