Chapter 5: Using Asymmetric and Hybrid Encryption in Node.js
In the previous chapter, Chapter 4, Symmetric Encryption in Node.js, we looked at how to protect the confidentiality of data by encrypting it using symmetric ciphers. Algorithms like the ones we used (AES and ChaCha20-Poly1305) are highly secure and fast, but they use a single key (in this case, a shared key) for both encryption and decryption. Consequently, to send an encrypted message to another person, both parties need to know the shared key too: safely transmitting that over an insecure channel (such as the internet) can become a problem.
As we briefly mentioned in the previous chapter, for these situations, it's often convenient to leverage a different class of cryptographic operations: asymmetric cryptography, also called public-key cryptography, since it uses two kinds of keys – a public key and a private key. RSA is one of the most popular and widely adopted algorithms for public-key encryption and...