Embeddable OpenSSL RSA Encryption in Javascript

RSA Public/Private keys is the de facto security encryption method for securing data. Today I'll be showing you how to encrypt and decrypt your data with JSEncrypt. We'll be creating OpenSSL public and private keys through terminal for JSEncrypt.

Creating OpenSSL keys

Creating OpenSSL private and public keys is pretty simple. All you have to do is execute these shell commands.

We'll be taking the contents of the public and private keys and then using them with the JSEncrypt library.

Creating a Javascript class

Let's create a Javascript class that utilizes JSEncrypt and the Public and Private Keys to encrypt and decrypt data.

Utilizing the Javascript class

Now that we have a simple but elegant class to encrypt or decrypt data. Let's utilize it in Node.js. Please note the Node.js implementation uses FS and is not browser compatible.

Note that the decrypted data will be "Hello world!" and the encrypted data will be some random RSA hash.