Skip to content
Bren2010 edited this page Oct 31, 2014 · 2 revisions

The simplest version of SJCL can be downloaded here.

However, if you want to use any of the extensions like ECC or SRP, then you'll have to clone and compile the file yourself.

$ git clone https://github.com/bitwiseshiftleft/sjcl.git
$ cd sjcl
$ ./configure # Requests for extensions go here, e.g. --with-ecc --with-srp
$ make sjcl.js
$ make test  # If any of the tests fail, beware.

From there, you can pull out sjcl.js and import it into your own project in the typical way.

For browser apps,

<html>
    <head>
        ...

        <script type="text/javascript" src="./sjcl.js"></script>
    </head>

    ...
</html>

and for Node.js apps,

var sjcl = require('./sjcl.js')

Hello World!

As a little sanity check, a simple SJCL program might work as follows:

var sjcl = require('./sjcl.js')

var ciphertext = sjcl.encrypt("password", "Hello World!")
var plaintext = sjcl.decrypt("password", ciphertext)

console.log(ciphertext)
console.log(plaintext)

(With <script> tags and alerts instead, for browsers.) The expected output is something like this:

{"iv":"A0DOQPxWAlJ5LHjoyhGWcw==","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Kk+ws1Xj0Xo=","ct":"NCPpLCHLLO5mBOGpSUpHdXPgKZA="}
Hello World!

The iv and ct tags in the encrypted object should have different values from the above (and each successive time you run the program), but still have the same general shape (encoding / length). The behavior of salt isn't important as long as the rest of the encrypted object is the same as the above.