Mcrypt is a simple crypting program, a replacement for the old unix crypt. The companion to MCrypt is Libmcrypt, which contains the actual encryption functions themselves, and provides a standardized mechanism for accessing them.
Mcrypt can be used with PHP program, also it it's available for the command line.
You need to compile PHP with the --with-mcrypt[=DIR] parameter to enable this extension. DIR is the mcrypt install directory. Make sure you compile libmcrypt with the option --disable-posix-threads.
=================================
For Ubuntu Linux add a line:
extension=php_mcrypt.so
to the file /etc/php5/apache2/php.ini
and restart network:
sudo /etc/init.d/networking restart
=================================
For recent versions of mcrypt, you must also use the compile option "--enable-dynamic-loading", so you need both of these:
--disable-posix-threads --enable-dynamic-loading
For details please visit the following links.
=============================
http://in.php.net/mcrypt
http://mcrypt.sourceforge.net/
=============================
Here is an sample use of Mcrypt with PHP coding.
=========================================
// a new proCrypt instance
$crypt = new proCrypt;
// encrypt the string
$encoded = $crypt->encrypt( 'your message');
echo $encoded."\n";
// decrypt the string
echo $crypt->decrypt( $encoded );
?>
=========================================
Here is the the procedure to install Mcrypt to use it at the command line option.
Download the source file using the following command.
--------------------------------------------------------------------
wget http://www.ottolander.nl/opensource/mcrypt/mcrypt-2.6.4.tar.bz2
--------------------------------------------------------------------
Unzip and extract it.
--------------------------------------------------------------------
bunzip2 mcrypt-2.6.4.tar.bz2
tax -xvf mcrypt-2.6.4.tar
--------------------------------------------------------------------
Here you have to remember that for mcrypt-2.6.4 you need to install libmhash 0.8.15 otherwise you will get such type of error below.
----------------------------------------------------------------------------------
"You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net/"
----------------------------------------------------------------------------------
In that case you can install libmhash using the following command or you can install libmhash through source or rpm.
=======================
yum install mhash*
=======================
For mcrypt-2.8.* does not have such type of libmhash dependency.
Now configure and install it through the following way.
======================
cd mcrypt-2.6.4/
./configure
make clean
make test
make
make install
======================
Here the use of Mcrypt through command line is given below.
When encrypting or decrypting a file, a new file is created with the extension .nc and mode 0600. The new file keeps the
modification date of the original. The original file may be deleted by specifying the -u parameter.
Examples
Encrypt test.txt file:
$ mcrypt test.txt
Output:
Enter the passphrase (maximum of 512 characters)
Please use a combination of upper and lower case letters and numbers.
Enter passphrase:
Enter passphrase:
A new file is created with the extension .nc i.e. data.txt.nc:
=================
$ ls test.txt.nc
$ cat test.txt.nc
=================
Decrypt the test.txt.nc file:
=================
$ mcrypt -d test.txt.nc
Output:
Enter passphrase:
File test.txt.nc was decrypted.
=================
Verify that file was decrypted:
=================
$ ls test.txt
$ cat test.txt
=================
Delete the input file if the whole process of encryption/decryption succeeds (pass -u option):
=================
$ mcrypt -u test.txt
OR
$ mcrypt -u -d test.txt.nc
=================
That's all.