Mcrypt is a replacement command of one of the popular Unix Crypt command. Crypt in UNIX was one of the file encryption tools which were using one of the popular algorithms similar to World War II enigma cipher. Mcrypt is also the similar command and it provides same functionality. So, we can say Mcrypt is a simplest type of modern crypting program. It uses today’s modern algorithms like AES to encrypt the data. Libmcrypt is called a companion. This is a kind of library code which holds all encryption functions that can be easily used. We can implement different kind of cryptographic algorithms and most of them are stream ciphers and block ciphers. Most common algorithms used by Mcrypt program are blowfish, arcfour, enigma, GOST, LOKI97, RC2, serpent, twofish, threeway, XTEA and wake.
Mcrypt also allows us to make use of different types of functions for encryptions and they don’t need to make any changes in the coding part. It also helps users to encrypt the data without making use of cryptographers. When we actually encrypt or decrypt any file, a new file with .nc extension is created. This file will have a mode 0600. This new file will have the same modification date like the original one. Even we can also delete the original file by specifying –u option in the command. If you don’t specify any filename in this command then by default standard input value will be encrypted and the result will be printed on the standard output.
This option will list the entire available encryption algorithm.
root@LinuxServer Desktop] # mcrypt –list
This command will encrypt the given file with new name filename.nc. It will make use of blowfish algorithm. It will also ask us to enter passphrase 2 times.
root@LinuxServer Desktop] # mcrypt –a blowfish filename
This command will decrypt the file filename.txt.nc to filename.txt.
root@LinuxServer Desktop] # mcrypt –d filename.txt.nc
This command will display the help for the whole mcrypt command with all its options.
root@LinuxServer Desktop] # mcrypt –-help
If you want to encrypt the data.txt file then following command will be used.
root@LinuxServer Desktop] # mcrypt data.txt
Enter the passphrase (maximum of 512 characters)
Please use the combination of upper and lower case letters and numbers.
Once, this command is executed it will create a new encrypted file with extension .nc. So, the name of the new file would be data.txt.nc. You can view the same file with following command:
# ls data.txt.nc
# cat data.txt.nc
If you want to decrypt the file then you can use the following command.
# mcrypt –d data.txt.nc
File data.txt.nc was decrypted.
If you want to delete the input file after your encryption or decryption process is successful then you can use the following command.
root@LinuxServer Desktop] # mcrypt –u data.txt
root@LinuxServer Desktop] # mcrypt –u –d data.txt.nc
While encrypting or decrypting any file with this command it will ask us to enter passphrase. Make sure that the passphrase we enter should have 512 characters maximum length. When the file is encrypted, this passphrase is generally transformed with the help of some key generation algorithm. The output of this is normally used as the key for it.