Wednesday, August 20, 2014

Encrypting text/files in unix

Encryption are of two types:
  1. Symetric encryption uses same key for encryption and decryption.
  2. Asymetric used key pair to encrypt and decrypt, i.e one key used to encrypt and another key used to decrypt; usually it is by public and private key.
In unix system use the following for :
Asymmetric encryption:
Step 1: Generate private key
Option 1:
openssl genrsa -out private.pem -des3 1024 # this would ask for a pass phrase=
Option 2:
openssl genrsa -out private.pem 4096 ##this will not ask for pass phrase
Step 2: Generate public key
openssl rsa -in private.pem -pubout -out public.pem
Step 3: Encrypt text file
openssl rsautl -encrypt -inkey public.pem -pubin -in file.txt -out file.ssl
Step 4: Decrypt text file
openssl rsautl -decrypt -inkey private.pem -in file.ssl
Symmetric encryption:
To encrypt:
openssl aes-256-cbc -a -salt -k <key> -in <input_file> -out <output_file_name>
To decrypt:
openssl aes-256-cbc -a -d -salt -k <key> -in <encrypted_file>
Now some theory, i got it from google search,
Asymmetric is as follows:
asymmetric

Symmetric is as follows:
symmetric

No comments:

Post a Comment