JAVAScript Public Key Encryption Demo

Here's everything you need to do secure, public key, browser-based transactions. I'll be working to integrate it with the shopping cart system later, but you can see where we're at. In this last version (1/25/2001) I've completely rewritten the arbitrary-precision math modules so we're quite a bit faster now.

First you need to generate a key pair. (Actually, it's a trio.) This is the slowest part. Pick how large a key you want. Larger keys are more secure, but take longer to generate, and somewhat longer to use (especially decrypting the orders). 512 bit key modulos (32 byte keys, ie p and q are 256 bits each) are still considered somewhat secure. My browser took almost 6 minutes to generate a key of this size. Try a smaller one first, like 8 bytes and multiply that time by 4 to see how long it might take for you.

Encrypting the orders takes very little time, maybe a second or two, but those decrypting will notice a definate lag (22 seconds for me).

Note that many browsers require you to NOT cancel the script after it is taking a while to generate the keys. I've tested this on InternetExplorer 5 (win). If you find it works/doesn't work with another browser, let me know. I've been told that Netscape is much slower than Microsoft for this type of thing.

key bytes:
prime factor p: prime factor q:
(Note: these are used to build your key values.)
Public Modulo (p*q):
Private exponent (d):
Public exponent (e):
text:
Decrypting takes seconds
This took seconds

How to use these:

This is free software.

Generate a key trio. For example, when I did I got:

Note: this example is trivially insecure

Put a copy of crypto.js on your hard drive and on the server. Then add the following to your public script on your server:

And put the following in your private script (probably on your local hard disk -- not on the internet -- if your private key is found this whole thing is useless.)

Ok, so you might want to do something more interesting than just put the data into document.form.text.value (this assumes you have a <form name="form"> in your document, by the way).

Enjoy!

John

Change log

1/25/01 -- concluding massive rewrite including Maurer's provable primes and Barrett's modular reduction; increased speed by 10 - 100 times
1/3/01 -- added sieve to prime number locator -- increasing speed lots!