This post explains how to encrypt and decrypt a file using symmetric key. In symmetric algorithms the security depends on the strength of the key as the encryption and decryption key is the same. The strength of the key depends on the key size. Key size is the number of bits in the key. This key has to be agreed by both the sender and receiver before the communication starts. The security of the algorithm depends on the secrecy of the key.
Consider a file ‘secret.txt’ with the following content
Secret key is 98234
Now, we encrypt it with a symmetric key using gpg.
gpg --symmetric secret.txt
This asks for a pass-phrase, which is the key.
The cipher algorithm used here is CAST5. CAST5(or CAST-128) is a block cipher. Block ciphers divides the message into blocks and each block is encrypted at a time. The key used for encrypting each block is the same. CAST5 has a fixed block size of 8 bytes. You can read more about CAST5 here.
Now, the encrypted file ‘secret.txt.gpg’ is created.
The content of secret.txt.gpg is:
<8c>^M^D^C^C^BÊÏñT<96>ÅGc`É1 7NA!áW<95>i^Y<98>s1 -lÐ^\j°ã[;$qs^GsÛ^?^<9d> /n<99>ÞÜ<87>äâÃ½D,^OM£¸ù
To decrypt, type the following command
gpg --decrypt secret.txt.gpg
This outputs the following
gpg: CAST5 encrypted data gpg: encrypted with 1 passphrase Secret key is 98234 gpg: WARNING: message was not integrity protected
Symmetric keys are useful when to protect any files in your own PC.