

In the real world, we would give our public key publicly, and anyone would be able to use the public key to encrypt data, send it to us, and only we would be able to read that data (using our private key that only we will have). In order to encrypt it, we need to first create our Public-Private key pair. OK, so now we have some secret data to encrypt 🎉 This is some arbitrary data created using Node.js's crypto module. You should now have a file called data_to_encrypt.txt in the project root. To create some data to encrypt, run this command You don't need to npm i as there are no dependencies, and the crypto module comes with node.

I'm writing this with code samples that you can run to:Įxport it, and write it to your file system (as public.pem & private.pem files)Ĭreate some sample data to encrypt (this is our secret we don't want anyone else knowing)Įncrypting said data, saving it in a file so we can see what it looks likeĭecrypting this encrypted data to get our original secret data Where it fell apart for me was actually implementation, since the keys created were in-memory and ephemeral.

*This post will explain the RSA algorithm, and how we can implement RSA Encryption, Decryption and Signing in Node.js…*(Please do read this article since I don't cover this in the post) RSA Encryption, Decryption and Signing in Node.js (Javascript) - With Examples This is a great article I came across that explains it well: Node.js comes with a 'crypto' module that helps you create public and private key pairs to use public-key cryptography.
