Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement public/private key cryptography in SJCL?

I have used Stanford Javascript Crypto Library (SJCL) for symmetric AES encryption (based on the examples on their demo page). However I have an additional requirement to generate a key pair, encrypt data with a public key, and decrypt data with a private key. Some of the class names suggest this might be possible in SJCL, but I was wondering if anyone could help with an example of how it's done. I'm not concerned at this stage with private key storage, just the in-memory generation and use of a public/private key pair.

If it isn't possible, I'd be interested in recommendations for an alternative library that will cover both AES and public key cryptography - but I'm aware this is something I could research myself! So mainly I'm curious to know if the library I have started using can cover all my needs or whether I need to look into an alternative.

like image 268
waifnstray Avatar asked Feb 11 '14 11:02

waifnstray


Video Answer


1 Answers

In fact it is possible to implement private/public encryption using the ECC module. If you are a pro you can check the api documentation at http://bitwiseshiftleft.github.io/sjcl/doc/.

If you want an example of how its done, you can go through

http://justinthomas.pro/crypto/test.html http://justinthomas.pro/crypto/ repository url

You can see the SJCL ECC implementation in action here (key generation included)

Also this might be helpful https://github.com/bitwiseshiftleft/sjcl/issues/134

P.S. Elliptic curve cryptography (ECC) is an approach to public-key cryptography based on the algebraic structure of elliptic curves over finite fields. 256-bit ECC public key should provide comparable security to a 3072-bit RSA public key http://en.wikipedia.org/wiki/Elliptic_curve_cryptography

like image 126
edocabhi Avatar answered Nov 15 '22 14:11

edocabhi