Gad! I have spent all morning trying to --- password protect a static html page. How in the hell does HN have a story about the exact topic I've been struggling with appear just a dozen or so hours after I started working on it. Wow. I was _extremely_ happy to see this posted. However when I click the link I am taken to the library I had initially tried and had to reject. Without getting into the crypto side of thing…
Something similar has been posted before some time ago: https://news.ycombinator.com/item?id=34083366
Password protect a static HTML page
141–150 of 294 posts
Re: Password protect a static HTML page
#142Earlier quoted context omitted.
Supposedly browsers are more ubiquitous on the recipient side than whatever other tools you might use.
I was thinking of editing my comment to add "Or be able to support filetypes other than HTML", but I suppose in our glorious "everything is the browser" future, filetypes other than HTML are as anachronistic as 8" floppy disks. Sigh.
Re: Password protect a static HTML page
#143Earlier quoted context omitted.
I don't know what "being a stream" has to do with anything (you should virtually always use "stream" modes of AES); the meaningful distinction between CBC and GCM is that GCM authenticates the ciphertext, so you can't tamper with it.
> so you can't tamper with it. ... if the API provided is correctly designed, and either the language made it practical to design the API in a misuse-resistant way /or/ the programmer was actually careful and used it properly. We both know it's way more likely the problem in your actual system is "Oops, we use the bogus plaintext here despite the validation error" than "Dastardly enemy cryptographers have made a brea…
Re: Password protect a static HTML page
#144Earlier quoted context omitted.
So use WebCrypto, instead of the cabinet of curiosities that is crypto-js. (Or, better yet, don't do stuff like this at all, because a browser window is simply an awful setting for serious cryptography).
WebCrypto only works in secure contexts which is a significant limitation (https origins only)
If you are serving out an encrypted HTML page insecurely, your users are already hosed, because someone on the path could inject a script that sends the password to evil[.]com when they type it in.
Re: Password protect a static HTML page
#145I'm not a cryptographer, but I'm pretty sure that CBC ( https://github.com/robinmoisson/staticrypt/blob/main/lib/cry... ) should be replaced with GCM ( https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypt... ) since this is not a stream. https://security.stackexchange.com/questions/184305/why-woul... (also, use the built-in WebCrypto API instead of the crypto-js package)
CBC is far easier to implement than GCM mode. I bet that most programmers cannot implement a Galois Field in Javascript. Meanwhile, CBC is just "encrypt then xor".
Re: Password protect a static HTML page
#146Re: Password protect a static HTML page
#147It should take you no less than 10 minutes ;)
Re: Password protect a static HTML page
#148Earlier quoted context omitted.
As I remember it, the balance of the bytes in the AES block are used for the counter. At any rate, the convention is essentially universal.
Sounds above my (current) head. Here I thought GCM was some modern foolproof/footgunless design.
Re: Password protect a static HTML page
#149Earlier quoted context omitted.
Not going to pretend that I know what the most of the stuff mean, or if it is even safe enough, but I've followed the MDN articles and put together this TypeScript snippet [1]. Maybe somebody could comment on it? Also sorry for the long link. Is there any accepted way to post a shorted URL? Edit: added a corrected version [2] [1]: https://www.typescriptlang.org/play?#code/DYUwLgBAbiDGYHsBOE... [2]: https://www.typesc…
If you call "encrypt" more than once in that code, you'll leak the authentication key. Every invocation of GCM encryption needs a unique nonce. Cryptography nerds will chastise you for using a random nonce (there theoretically isn't enough room in the GCM nonce space to safely encrypt large numbers of message with random nonces), but the alternative (using a counter) is even more hazardous. This problem motivates a l…
1: https://csrc.nist.gov/csrc/media/Projects/crypto-publication...
Re: Password protect a static HTML page
#150Earlier quoted context omitted.
Something similar has been posted before some time ago: https://news.ycombinator.com/item?id=34083366
Which in turn has inspired the creation of PrivacyProtect [0]. It allows to do basically the same thing as the other applications, but in my opinion the interface is better, it also allows you to directly select a file which I guess is easier than copying the contents, it also means you can just select an image file for instance or some other type of file other than a web page. [0]: https://www.privacyprotect.dev/
I don't get it.
Great UI, though. But I still don't get it.