Home  >  Article  >  php教程  >  PHP中如何安装 Mhash扩展库

PHP中如何安装 Mhash扩展库

WBOY
WBOYOriginal
2016-06-13 10:27:281679browse

综述:0.8.3版的Mhash扩展库支持12种混编算法,仔细检查Mhash v.0.8.3的头文件mhash.h可以知道,它支持下面的混编算法:
CRC32 HAVAL160 MD5
CRC32B HAVAL192 RIPEMD160
GOST HAVAL224 SHA1
HAVAL128 HAVAL256 TIGER
如何安装Mhash扩展库?
象Mcrypt一 样,Mhash也没有包括在PHP软件包中,下面是安装过程(非Windows):
首先,下载Mhash扩展库(http://sourceforge.net/projects/mhash/ )
gunzipmhash-x.x.x.tar.gz
tar -xvfmhash-x.x.x.tar
./configure
make
make install
cd
./configure -with-mhash=[dir] [--other-configuration-directives]
make
make install
然后,象Mcrypt一样,根据PHP在互联网服务器软件上的安装方式,可能需要对Mhash进行其他的配置。
对于Windows用户而言, http://www.php4win.de中有一个很好的包括Mhash扩展库在内的PHP软件包。只要下载并进行解压缩,然后根据其中的readme.first文档中的指令进行安装即可。
如何使用Mhash?
对信息进行混编非常简单,看一下下面的例子:
<?php
$hash_alg = MHASH_TIGER;
$message = "These are the directions to the secret fort. Two steps left, three steps right, and cha chacha.";


$hashed_message = mhash($hash_alg, $message);
print "The hashed message is ". bin2hex($hashed_message);
?>
执行这一段脚本程序将得到下面的输出结果:
The hashed message is 07a92a4db3a4177f19ec9034ae5400eb60d1a9fbb4ade461
在这里使用bin2hex()函数的目的是方便我们理解$hashed_message 的输出,这是因为混编的结果是二进制格式,为了能够将它转化为易于理解的格式,必须将它转换为十六进制格式。
需要注意的是,混编是单向功能,其结果不依赖输入。
Mhash还有其他一些有用的函数。例如,我们需要输出一个Mhash支持的算法的名字,由于 Mhash支持的所有算法的名字都以MHASH_开头,因此,可以通过执行如下的代码完成这一任务:
<?php
$hash_alg = MHASH_TIGER;
print "This data has been hashed with the".mhash_get_hash_name($hashed_message)."hashing algorithm.";
?>>
得到的输出是:
This data has been hashed with the TIGER hashing algorithm.
关于PHP和加密需要注意什么问题?
PHP加密需要注意的一个重要问题是在服务器和客户端之间传输的数据在传输过程中是不安全的!PHP是一种服务器端技术,不能阻止数据在传输过程中泄密。因此,如果想实现一个完整的安全应用,建议选用 Apache-SSL或其他的安全服务器。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn