Symmetric Encryption using Openssl
Assume
private.key is the name of your private key which is given by you , you can give any name
message.enc is the name of your encrypted file which is given by you , you can give any name
message.dec is the name of your decrypted file which is given by you , you can give any name
Step 1. Generate a private key using the command
openssl rand -hex -out private.key
Step 2. Encrypt the message with private key
openssl aes-256-cbc -in message.txt -out message.enc -e -a
when it asks you to enter a password enter any password that you want
Step 2. Decrypt the message with private key
openssl aes-256-cbc -in message.enc -out message.dec -d -a
Asymmetric Encryption using Openssl
Assume
private.key is the name of your private key which is given by you , you can give any name
public.key is the name of your public key which is given by you , you can give any name
data.txt is the name of your file you are going to encrypt which is given by you , you can give
any name
data.enc is the name of your encrypted file which is given by you , you can give any name
data.dec is the name of your decrypted file which is given by you , you can give any name
Steps
Step 1. Generate a private key using the command
openssl genrsa -out private.key 2048
Step 2. Generate a public key using the command
openssl rsa -in private.key -pubout –out public.key
Step 3. Encrypt with public key
openssl pkeyutl –encrypt - pubin –inkey public.key -in data.txt -out data.enc
Step 4. Decrypt with private key
openssl pkeyutl –decrypt –inkey private.key -in data.enc -out data.dec
Sign a certificate using openssl
m.txt is the name of your file you are going to sign which is given by you , you can give any
name
m.sign is the name of your signed file which is given by you , you can give any name
Method One
Steps
Step1. Sign with private key using the command
openssl pkeyutl –sign -in m.txt -inkey private.key –out m.sign
Step2. Signature verification with public key using the command
openssl pkeyutl –verify –pubin -inkey public.key -sigfile m.sign -in m.txt
Method Two
Steps
Step1. Sign with private key using the command
openssl sha1 –sign - private.key –out m.sign m.txt
Step2. Signature verification with public key using the command
openssl sha1 –verify - public.key –signature m.sign m.txt