综述:Mcrypt 2.4.7是一个功能强大的加密算法扩展库,它包括有22种算法,其中就包括下面的几种算法:Blowfish RC2 Safer-sk64 xtea Cast-256 RC4 Safer-sk128 ......
综述:Mcrypt 2.4.7是一个功能强大的加密算法扩展库,它包括有22种算法,其中就包括下面的几种算法:
Blowfish RC2 Safer-sk64 xtea Cast-256 RC4 Safer-sk128 DES RC4-iv Serpent Enigma Rijndael-128 Threeway Gost Rijndael-192 TripleDES LOKI97 Rijndael-256 Twofish PanamaSaferplus Wake
如何安装Mcrypt?
在标准的PHP软件包中不包括Mcrypt,因此需要下载它,下载的地址为:ftp://argeas.cs-net.gr/pub/unix/mcrypt/ 。下载后,按照下面的方法进行编译,并把它扩充在PHP中:
下载Mcrypt软件包。
gunzipmcrypt-x.x.x.tar.gz tar -xvfmcrypt-x.x.x.tar ./configure --disable-posix-threads make make install cd to your PHP directory. ./configure -with-mcrypt=[dir] [--other-configuration-directives] make make install
根据你的要求和PHP安装时与服务器作适当的修改。
如何使用Mcrypt扩展库对数据进行加密?
首先,我们将介绍如何使用Mcrypt扩展库对数据进行加密,然后再介绍如何使用它进行解密。下面的代码对这一过程进行了演示,首先是对数据进行加密,然后在浏览器上显示加密后的数据,并将加密后的数据还原为原来的字符串,将它显示在浏览器上。
使用Mcrypt对数据进行加、解密
<?php // Designate string to be encrypted $string = "Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference.";
// Encryption/decryption key $key = "Four score and twenty years ago";
// Encryption Algorithm $cipher_alg = MCRYPT_RIJNDAEL_128;
// Create the initialization vector for added security. $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND);
// Output original string print "Original string: $string ";
// Encrypt $string $encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_CBC, $iv);
// Convert to hexadecimal and output to browser print "Encrypted string: ".bin2hex($encrypted_string)."
1/2 1 2 下一页 尾页 |