Live data from Hacker News

Javascript encryption

vincentcheung.ca

11–20 of 63 posts

Re: Javascript encryption

#11
post #8
post #7

Earlier quoted context omitted.

If you are running javascript on a page from a server, you are trusting the server with your plaintext.

Seems like browser extensions would be the way to go. Here's the SJCL demo: http://bitwiseshiftleft.github.com/sjcl/demo/

Yes, exactly. I would love to have cross device SSO and authentication. Having proper cryptography available in the browser (either built-in or through a extension) would make that easier to make. As a bonus: phishing resistant.

Re: Javascript encryption

#13
post #2

John Walker made that already at least 6 years ago: http://www.fourmilab.ch/javascrypt/ Moreover, Walker's code is public domain and he discusses security aspect, whereas the op link appears not to care about such things.

Similarly with Movable-Type's implementation: http://www.movable-type.co.uk/scripts/aes.html

http://www.movable-type.co.uk/ contains several very useful resources for implementing JS crypto.

Re: Javascript encryption

#14
post #7
post #6

What does this offer over SJCL? And for those asking in the thread, JS encryption is useful in that you never have to trust a server with your plaintext.

If you are running javascript on a page from a server, you are trusting the server with your plaintext.

You are trusting the server, you are trusting the quality of every line of code on the server that has a hand in generating the page content (since any DOM corruption flaw will let you trivially backdoor the encryption), and you're trusting every third party server from which HTML or JS content is sourced.

It's a terrible, terrible idea.

Re: Javascript encryption

#15
post #13
post #2

John Walker made that already at least 6 years ago: http://www.fourmilab.ch/javascrypt/ Moreover, Walker's code is public domain and he discusses security aspect, whereas the op link appears not to care about such things.

Similarly with Movable-Type's implementation: http://www.movable-type.co.uk/scripts/aes.html http://www.movable-type.co.uk/ contains several very useful resources for implementing JS crypto.

... which, implementing JS crypto, you should never do.

Re: Javascript encryption

#16
post #3

Could anyone explain what's the use case for encrypting text on a web page using JavaScript? I don't understand how this library is useful except for situation when used in Chrome extensions like the one used by LastPass. If this lib is used on a page to decrypt/encrypt user data before sending to the server, theoretically it's possible for the host to steal private key simply by injecting a JS code that copies user'…

It's worse than that. Among many other things, it's possible for any attacker with an XSS bug in any component of the DOM of that page (cached or fetched fresh) to steal keys. Modern browsers provide no way to verify the whole JS runtime to ensure that no function that your crypto depends on has been backdoored, but every JS implementation allows functions to be overridden.

It's the worst possible environment to implement crypto in, and you should never do it.

Re: Javascript encryption

#17
Be careful: if you are using a javascript library to encrypt data, you get protection from eavesdroppers, but not from man-in-the-middle attacks. If I can alter data that you send/receive over the wire, I can simply modify your aes function calls to xor the data with a predictable sequence that I generate. The only way to prevent this that I have thought of is to store the site (which has presumably already been acquired over a secure channel) locally on the client's machine, and make AJAX calls over the encrypted channel for fresh content.

Re: Javascript encryption

#19
post #3

Could anyone explain what's the use case for encrypting text on a web page using JavaScript? I don't understand how this library is useful except for situation when used in Chrome extensions like the one used by LastPass. If this lib is used on a page to decrypt/encrypt user data before sending to the server, theoretically it's possible for the host to steal private key simply by injecting a JS code that copies user'…

Suppose you want to store confidential data with the server. You trust the server owners to be the good guys, but you also know that data breaches happen (e.g. equipment theft, FBI seizures, backup tape leaks), so if/when the breach happens the thieves will have made off with encrypted copy of your data. The only way your data is jeopardized is one of the two cases:

1. The people maintaining the service turned out to be not trustworthy, and have been harvesting the keys all along.

2. The hackers took control of the server and injected code to harvest the encryption keys for long enough to catch you in the net.

If you look at the relative probabilities of these two events compared to a straight-up data leak, we're looking at orders of magnitude reduction in risk. Most people who did the right thing in the past are in the habit of doing the right things, so you can lean on the host's reputation - we've been doing that for thousands of years. Code injection on the site is much less likely than the data leak, and it is a lot less fruitful for the attacker as he would have to sit there undetected and wait for enough users to punch in their keys.

Re: Javascript encryption

#20
post #15
post #13

Earlier quoted context omitted.

Similarly with Movable-Type's implementation: http://www.movable-type.co.uk/scripts/aes.html http://www.movable-type.co.uk/ contains several very useful resources for implementing JS crypto.

... which, implementing JS crypto, you should never do.

If your goal is to share state secrets, then no, I wouldn't suggest using JS for crypto.

If your goal is to no longer be low hanging fruit for attackers, then yes, I would recommend it.

Post reply on HN