Interoperability

167 views
Skip to first unread message

vincenzoml

unread,
Aug 31, 2012, 9:28:03 AM8/31/12
to sjcl-d...@googlegroups.com
Hi,

how can data encrypted in SJCL be decrypted using other languages? How difficult it is to get openSSL compatibility? 

thanks

Vincenzo

Mike Hamburg

unread,
Sep 1, 2012, 12:06:59 AM9/1/12
to sjcl-d...@googlegroups.com
Hi,

It's trickier than I'd like. You'll need a JSON parser, a base64 decoder, and a crypto suite capable of PBKDF2 (with SHA256), AES and CCM mode, and you'll have to more or less re-implement SJCL's dataflow. Parse the JSON; send the salt and password through PBKDF2 with the right number of iterations; pass the key and IV into CCM; decrypt the ciphertext.

Cheers,
-- Mike

Maarten Bodewes

unread,
Sep 2, 2012, 7:17:50 AM9/2/12
to sjcl-d...@googlegroups.com
On Sat, Sep 1, 2012 at 6:06 AM, Mike Hamburg <mi...@shiftleft.org> wrote:
> It's trickier than I'd like. You'll need a JSON parser, a base64 decoder, and a crypto suite capable of PBKDF2 (with SHA256), AES and CCM mode, and you'll have to more or less re-implement SJCL's dataflow. Parse the JSON; send the salt and password through PBKDF2 with the right number of iterations; pass the key and IV into CCM; decrypt the ciphertext.

Besides that you need to take care that you follow SJCL conventions. I
know since I created an (unfinished) SJCL compatible Java library. For
instance, binary data is not directly supported by JSON, and SJCL does
not use the '=' padding character for base64 encoding.

CCM mode encryption is also something that is not so commonly
available, and it is a bit of a pain to work with, certainly much
worse in that regard than GCM.

That said, as the main functionality of my Java code is there, it is
certainly possible.

Regards,
Maarten

Shlomi Cohen-Ganor

unread,
Nov 18, 2012, 11:03:08 AM11/18/12
to sjcl-d...@googlegroups.com
Could you by any chance share your unfinished SJCL compatible Java library?
I need to encrypt something in javascript and then decrypt it in Java.

Many thanks

Pablo Nussembaum

unread,
Nov 15, 2016, 1:37:01 PM11/15/16
to SJCL discussion
Since I haven't any proper solution to encrypt/decrypt in plain java.
I'm using nashorn to run the sjcl.js directly.
Here is a snippet:
    private static void test() throws ScriptException {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
        engine.eval(new InputStreamReader(Crypto.class.getResourceAsStream("sjcl.js")));

        Object eval = engine.eval("sjcl.encrypt('password', 'Hello World')");
        System.out.println(eval);

        eval = engine.eval("sjcl.decrypt('password', '" + eval + "')");
        System.out.println(eval);
    }

Reply all
Reply to author
Forward
0 new messages