faqts : Computers : Programming : Languages : PHP : Common Problems : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 33 people (36%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How can I encrypt and decrypt data in PHP?

Jun 28th, 1999 01:39
Nathan Wallace, Sascha Schumann


From http://www.php.net/manual/ref.mcrypt.php3

This is an interface to the mcrypt library, which supports a wide
variety of block algorithms such as DES, TripleDES, Blowfish (default),
3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB,
CFB and ECB cipher modes. Additionally, it supports RC6 and IDEA which
are considered "non-free". 

To use it, download libmcrypt-x.x.tar.gz from here and follow the
included installation instructions. You need to compile PHP with the
--with-mcrypt parameter to enable this extension. 

mcrypt can be used to encrypt and decrypt using the above mentioned
ciphers. The four important mcrypt commands (mcrypt_cfb(), mcrypt_cbc(),
mcrypt_ecb(), and mcrypt_ofb()) can operate in both modes which are
named MCRYPT_ENCRYPT and MCRYPT_DECRYPT, respectively.