This repository contains two basic examples of encryption using Node.js. These examples cover both symmetric and asymmetric encryption techniques, forming part of the groundwork for understanding SSL (Secure Sockets Layer) and how encryption works at its core.
- symmetric.js: Demonstrates how symmetric encryption works, using a secret key to both encrypt and decrypt messages.
- asymmetric.js: Demonstrates how asymmetric encryption works, using a public key to encrypt messages and a private key to decrypt them.
Both examples are simple and easy to understand, providing a foundation for learning how encryption functions, which is essential to understanding SSL.
In symmetric encryption, the same key is used for both encryption and decryption.
- Algorithm:
aes-256-ecb
(AES-256 with ECB mode) - Key: A 256-bit secret key is randomly generated.
- The
secretKey
is used to encrypt a message. - The same
secretKey
is used to decrypt the message.
node symmetric.js
Encrypted Message: <hex_encoded_encrypted_message>
Decrypted Message: This is a secret message
In asymmetric encryption, a public key is used to encrypt messages, and a private key is used to decrypt them.
- Algorithm: RSA with a 2048-bit key pair
- Keys: A public/private key pair is generated.
- The
publicKey
encrypts the message. - The corresponding
privateKey
decrypts the message.
node asymmetric.js
Encrypted Message: <hex_encoded_encrypted_message>
Decrypted Message: This is a top secret message
- Clone this repository:
git clone https://github.com/DevRelSquad-blogs/SSL_certificate_generator/encryption
- Install Node.js if you haven't already: Download Node.js.
- Run the examples:
- For symmetric encryption:
node symmetric.js
- For asymmetric encryption:
node asymmetric.js
- For symmetric encryption:
This is the first part of a broader guide on how SSL works. In the next part, we'll cover how to generate your own SSL certificate and test it on your local machine. Stay tuned for more practical insights into securing your web applications using SSL!
Feel free to contribute or raise issues if you have any questions! 😊