←back to #AskDushyant

Enchanted Crypt: Secrets of Symmetric and Asymmetric Encryption Spells

Greetings, brave tech alchemist of the digital realm! Welcome to the magical world where ancient encryption spells weave intricate patterns of secrecy and security. In this enchanting blogpost, we shall embark on a quest to unlock the mysteries of encryption and decryption, unveiling the powers of both symmetric and asymmetric spells with shell scripting. Gather your magical artifacts, for the enchanted crypt awaits!

Marvels of Symmetric Sorcery

In the mystical land of symmetric encryption, a single magical key holds the power to both lock and unlock the enchanted gates. Think of it as a spellbook that can only be deciphered by the rightful heir. With this spell, we can encase messages in an unbreakable shield, ensuring they can only be revealed to those who possess the key.

Symmetric Encryption Spell:

#!/bin/bash

# Crafting the magical key
key=$(openssl rand -base64 32)

# Enchanting our message
message="Greetings from the Enchanted Crypt!"

# Casting the encryption spell
ciphertext=$(echo -n "$message" | openssl enc -aes-256-cbc -base64 -A -k "$key")

echo "Encrypted Message: $ciphertext"
echo "Magical Key: $key"

Symmetric Decryption Spell:

#!/bin/bash

# Encrypted data and key received from the encryption script
encrypted_data="encrypted_data_here"
key="key_here"

# Decrypt the data using AES-256-CBC symmetric decryption
decrypted_data=$(echo "$encrypted_data" | openssl enc -aes-256-cbc -d -base64 -A -k "$key")

echo "Decrypted Data: $decrypted_data"

Elegance of Asymmetric Alchemy

In the enchanted forest of asymmetric encryption, two distinct spells dance together – the public spell (Public Key) and the private spell (Private Key). The public spell can be shared openly, inviting messages from all corners of the realm, while the private spell, kept close to the heart, unveils the secrets hidden within. Together, they create an impenetrable fortress of security.

Asymmetric Encryption Spell:

#!/bin/bash

# Conjuring the magical keys to generate public and private key
openssl genpkey -algorithm RSA -out private_key.pem
openssl rsa -pubout -in private_key.pem -out public_key.pem

# Enchanting our message
message="Secrets of the Enchanted Crypt"

# Casting the encryption spell with the public key
ciphertext=$(echo -n "$message" | openssl rsautl -encrypt -pubin -inkey public_key.pem | base64 -w 0)

echo "Encrypted Message: $ciphertext"

Asymmetric Decryption Spell:

#!/bin/bash

# Encrypted data received from the encryption script
encrypted_data="encrypted_data_here"

# Decrypt the data using RSA private key decryption
decrypted_data=$(echo "$encrypted_data" | base64 -d | openssl rsautl -decrypt -inkey private_key.pem)

echo "Decrypted Data: $decrypted_data"

And there you have it, noble enchanters of the digital realm! You’ve mastered the ancient arts of symmetric and asymmetric encryption, transforming ordinary messages into cryptic incantations that only the worthy can decipher. As you venture forth in this magical journey, remember the importance of safeguarding your keys and incantations. May your spells be secure, and your enchanted crypts forever impenetrable. Until then, happy spell-casting, Cryptic Conjurers! 🧙‍♂️💻✨

#AskDushyant

Leave a Reply

Your email address will not be published. Required fields are marked *