ECC

108 views
Skip to first unread message

Justin Thomas

unread,
Nov 24, 2011, 9:58:54 PM11/24/11
to sjcl-d...@googlegroups.com
I'm trying to learn how the ECC functions in SJCL work. I've successfully used the framework to generate elGamal keys from the code in the ECC branch on GitHub, but can't find the functions that would allow me to use those to encrypt and decrypt information.

I've searched and can't find any documentation. Is there an example script somewhere that I could use as a template? Right now, I'm just using SpiderMonkey to get a feel for how it works from the command line.

Thanks in advance for any pointers!
Justin

Emily

unread,
Nov 26, 2011, 10:16:05 PM11/26/11
to SJCL discussion
Hi Justin,

Once you have an El Gamal key pair, you can use the kem (key
encapsulation mechanism) method of the public key to generate a
symmetric key and a tag for it. You can use the symmetric key to
encrypt data, and the tag to recover the symmetric key for decryption.
Here's an example:

var keys = sjcl.ecc.elGamal.generateKeys(192, 0);
var kem = keys.pub.kem(0);

// use kem.key to encrypt as normal
var ct = sjcl.encrypt(kem.key, data, params);

// use kem.tag to recover the key
var symKey = keys.sec.unkem(kem.tag)
// use symKey as normal in a call to sjcl.decrypt

Hope that helps,
Emily

>  smime.p7s
> 5KViewDownload

Justin Thomas

unread,
Nov 26, 2011, 10:20:20 PM11/26/11
to sjcl-d...@googlegroups.com
It does. I kind of figured out as much after much experimentation, but thank you for confirming!

So far, I really like what I'm seeing.

Reply all
Reply to author
Forward
0 new messages