Tag Archives: Symmetric-key encryption

File encryption and decryption using symmetric key

Symmetric-key encryption is the type of encryption where the key used to encrypt and decrypt a file is the same. Symmetric  key encryption can use two types of ciphers :

  1. Block Ciphers : Here, the message to be sent, is divided into blocks of fixed size and each block is encrypted using the same key. Thus similar blocks when encrypted using the same key give the same output (AES – Advanced Encryption Standard has 128 bits in a block).
  2. Stream Ciphers : In this cipher, each bit of the message to be encrypted, is encrypted separately.

Encrypting and decrypting a file using symmetric key :

Put the text to be encrypted into a file. Let the contents of the file to encrypted  be :
This is a secret.
The name of the file to be encrypted is secret.

savita@Amrita:~/secure_os$ gpg --symmetric secret

A password is prompted for, which is the key. A file called secret.gpg gets formed. This is the encrypted file. You can view the contents of the file.

savita@Amrita:~/secure_os$ cat secret.gpg
�vu�ƿѥ`�-Y���������V�|�*l5#` ��vf1#ah��v������8�

Now if you want to decrypt the file, run the following command :

savita@Amrita:~/secure_os$ gpg --decrypt secret.gpg

and enter the correct password. You get the following output which contains the text that you encrypted.

gpg: CAST5 encrypted data
gpg: encrypted with 1 passphrase
This is a secret. gpg: WARNING: message was not integrity protected

Bingo! You just encrypted and decrypted a file using a symmetric key. This uses the CAST5 algorithm for encryption.