最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
如何利Mcrypt扩展库进行加密和解密
时间:2008-01-24 编辑:简简单单 来源:一聚教程网
????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对数据进行加、解密 ????"; ????$decrypted_string = mcrypt_decrypt($cipher_alg, $key, ????$encrypted_string, MCRYPT_MODE_CBC, $iv); ????print "Decrypted string: $decrypted_string"; ?????> ??执行上面的脚本将会产生下面的输出: ????Original string: Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference. ????Encrypted string: 02a7c58b1ebd22a9523468694b091e60411cc4dea8652bb8072 34fa06bbfb20e71ecf525f29df58e28f3d9bf541f7ebcecf62b c89fde4d8e7ba1e6cc9ea24850478c11742f5cfa1d23fe22fe8 bfbab5e ????Decrypted string: Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference. ??上面的代码中两个最典型的函数是mcrypt_encrypt()和 mcrypt_decrypt(),它们的用途是显而易见的。我们使用了"电报密码本"模式,Mcrypt提供了几种加密方式,由于每种加密方式都有可以影响密码安全的特定字符,因此对每种模式都需要了解。对那些没有接触过密码系统的读者来说,赡芏?crypt_create_iv()函数更有兴趣,我们会提到它创建的初始化向量(hence, iv),这一向量可以使每条信息彼此独立。
尽管不是所有的模式都需要这一初始化变量,但如果在要求的模式中没有提供这一变量,PHP就会给出警告信息。
-
上一个: mysql常见出错代码
-
下一个: MySQL Join详解
相关文章
- python rsa 加密解密 07-10
- python无证书加密解密例子 10-25
- AES加密解密的例子小结 02-17
- DES(Data Encryption Standard)加密解密整理 01-12
- 用C#实现Des加密和解密 01-12
- 加密与解密 01-12