I followed the same road as you, you are probably better off implementing something like oAuth.
The problem with what you offer is that there is no absolutely reliable way to store the private key on the client machine, and now it is safe to get the public key on a server other than HTTPS (and if you use HTTPS, what is this point?)
If you really want to continue, there are some implementation options: http://shop-js.sourceforge.net/crypto2.htm
And you probably want something terribly annoying like PersistJS (http://pablotron.org/?cid=1557) to try to keep the private key as long as possible.
source share