shadcn.io is not affiliated with official shadcn/ui
Encryption Key Login Block for React
A split sign-in page where you drop a key file or paste a PEM key and a readout checks its BEGIN and END lines, its base64 body and shows its SHA-256 fingerprint, all in the tab.
Installation
Overview
Let people prove they hold a key before anything is sent, with this encryption key login block for React with Base UI. It's the sign-in of Keybarn, encrypted backups: the page's side rails run the full height of the screen and one band crosses it, split in two. The start side is the form, with a File Upload drop zone for a key file (.pem or .key) and, under it, a Textarea to paste the key into, with a "Use a sample key" button and a Shine Button to sign in. The end side is a readout, and it is real: as the key is chosen or pasted it checks the armor (a BEGIN line and a matching END line), checks that the body is base64 of a whole length, and works out the SHA-256 fingerprint of the decoded body with crypto.subtle, shown as SHA256:ab:cd:... with a Copy Button. A file is read with File.text(), and like the pasted text it never leaves the tab. On a phone the readout sits under the paste box. It's built from File Upload, Textarea, Field, Copy Button, Shine Button, Button and Guides, with CSS transitions only. For backup, vault and infrastructure tools whose users sign in with a key file.
FAQ
What stays in the tab, and how do I sign in for real?
All of it. The file is read with File.text() and the fingerprint is hashed with the browser's crypto.subtle, so the key is never uploaded, stored or logged, and the sample key is made up and opens nothing. Signing in waits less than a second, then says that nothing signed in. For a real product, never send a private key: sign a challenge from your server with it in the tab, or send only a public key or its fingerprint, and let the server decide.
What does the readout check?
That the first line reads -----BEGIN … KEY-----, that a last line reads -----END …----- with the same name, that the lines between are base64 with a length that is a multiple of 4, and that there is something in them. A problem is one sentence that names the line ("Line 3 has characters that aren't base64"). Signing in with a key that doesn't read puts that sentence under the paste box and moves focus there.
What is the fingerprint, and what is it for?
The SHA-256 hash of the key's decoded body, written as SHA256: and colon-separated hex pairs. Two copies of the same key give the same fingerprint, so you can compare it with the one your vault shows to be sure you picked the right file. On a page that isn't secure (plain http) the browser has no crypto.subtle, and the readout says it is working it out without ever finishing, so serve it over https.
Which files does the drop zone take?
One file at a time, .pem, .key or .txt, under 16 KB; anything else is refused with a line under the zone, and the status says the file wasn't read. Pressing the zone opens the file picker, and dropping a file on it reads it. The text lands in the paste box, so you can see and edit what was read.
How does the split work on a phone?
The form and the readout stack, and the readout stays under the paste box and above the button, so the result of choosing a key is on the screen when you press Sign in. From the large breakpoint the readout moves to the end side, drawn between the same two rules. The two copies share one state; the one you can't see is out of the tab order and the reading order.
Is it usable with a keyboard and a screen reader?
Yes. The drop zone is a labelled button that opens the picker, the paste box has a visible label and a problem line that is read, and the readout is a labelled section with a list of what was found. A single polite status line says what was read, copied or refused, and the result of signing in takes focus.
Related
- Pro
Hardware Key Login
Biometrics and keysA custody service's security-key page: a USB or NFC switch, three sign-in states, one button that waits for the key and then accepts it, and a drawing of a key and a port or a reader.
- Pro
A panel that decodes a pasted JWT in the page, with its header and payload in a tree, its claims set out and an HS256 signature really checked against a typed sample secret.
- Pro
A sign-in for a data-pipeline service where you paste a token and chips say whether it is a personal token or a JWT, with its length and expiry worked out from a typed rule, and a list of token formats.
- Pro
A sign-in for a messaging API with Password and API key as two tabs, where the key tab checks a key's prefix and length and shows a curl line that rewrites itself with the key masked.
- Pro
Passkey Login
PasswordlessAn online bank's sign-in page and its passkey chooser shown open over a drawn sign-in screen: two passkeys as radio rows, Cancel and Continue, a verifying step and a signed-in result, with the real dialog behind the Use your passkey button.
- Pro
Smart Card Login
Biometrics and keysA contractor portal's smart-card sign-in: a vertical rail of four steps (reader, card, certificate, PIN) beside one panel per step, with two certificates and three PIN attempts before the card locks.