Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

There are a few JavaScript AES implementations available such as Gibberish-aes

So assuming the AES algorithm has been implemented correctly in this library then it should be as secure as any other language implementation ? And if not why not ?

share|improve this question
Here is some discussion of Cryptography in Web browsers: JavaScript Cryptography considered harmful. –  Paŭlo Ebermann Oct 8 '11 at 16:23
Mostly the problems come with the fact you are bypassing half the issues which protect memory access from other processes and stuff, browsers have stuff in them so the AES keys used for one page can never be sent to another page through a blackbox encryption technique, if all is in javascript one can get such information easily using cross site scripting attacks and the like. –  ewanm89 Oct 8 '11 at 18:47
Also, you do have to do it properly, 100% properly. Even the openssl debian devs manage not to do this from time to time. –  ewanm89 Oct 8 '11 at 18:49
Article @PaŭloEbermann linked to says it all. Crypto in Javascript is not a good idea in my point of view - another bunch of reasons why rdist.root.org/2010/11/29/final-post-on-javascript-crypto –  Krzysztof Kotowicz Oct 10 '11 at 19:33
This library include AES is the best... cryptojs.altervista.org/secretkey.html –  user7648 Feb 10 '12 at 14:27
show 1 more comment

migrated from crypto.stackexchange.com Oct 8 '11 at 17:39

This question came from our site for software developers, mathematicians and others interested in cryptography.

2 Answers

AES is a specification that can be implemented in any programming language.

If you are thinking about doing encryption in JavaScript to avoid using https, this will not be secure: Transmitting the HTML file or any included JavaScript via an http connection allows an attacker to modify it. So in addition to doing the encryption it can send the information unencrypted to another server.

share|improve this answer
add comment

"Implementing the AES" means producing the precise ciphertext that the standard mandates for a given plaintext and key; we are talking about exact values, down to the last bit, so the general answer to your question is: yes, it is "as secure" as if it was implemented with any other language.

The paragraph above is about "secure" when applied to the protocol, i.e. in the view of an attacker who observes what travels on the wires. There is another meaning of "secure", when applied specifically to the implementations: it is the ability of the implementation of not leaking key information to an attacker who has physical (or utterly logical) access to the hardware. A Javascript implementation runs in the Web browser and cannot really hide anything from whoever has access to the Web browser and, in particular, its "debug script" features. But a C-based implementation cannot protect itself either against such a local attacker; so this notion is probably not the one you are using.

share|improve this answer
No, but a C based inplementation can't have someone inject another script onto the wire or cross sites scripts access to key variables, like keys and initialisation vectors. –  ewanm89 Oct 8 '11 at 18:50
@ewanm89 if the program file is downloaded via an insecure connection it can be manipulated. Manipulating compiled C code may be a bit harder than altering JavaScript code, but it is no magic. –  Hendrik Brummermann Oct 8 '11 at 19:18
Yes, but with javascript one doesn't have to even manipulate that code, that can add a whole second javascript code and just ask for the variables. This is runtime exploitation which generally requires an open service and an exploit for it or access already to the machine to do with C. –  ewanm89 Oct 8 '11 at 20:01
By sticking the code in javascript you are opening up a whole load of attack vectors just from the fact the browser is running several scripts on the page, and even if one couldn't just inject said file (say it's over https), one needs to be extremely carefull about any externally referenced javascript files (jquery, google analytics...) or any other content, and then there is cross site scripting on top. And I haven't even needed to attempt to break through any browsers sandbox. –  ewanm89 Oct 8 '11 at 20:06
@ewanm89, C programs can't be subverted via XSS, but they can still be subverted by buffer overflows, shell-injection, and plenty of other classes of attack. To keep a secret, you need to prevent subvertible code from accessing it. JavaScript is a safe-language w.r.t. a number of abstractions (inviolable closures, same-origin, ...) that allow sub-reference-graphs to be isolated, whereas C has only process boundaries. –  Mike Samuel Oct 9 '11 at 7:22
show 3 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.