crc32(),md5(),sha1()函数的简要理解与分析

一:int crc32 ( string str ) 

CRC的全称是循环冗余校验

生成 str 的 32 位循环冗余校验码多项式。这通常用于检查传输的数据是否完整

由于 PHP 的整数是带符号的,许多 crc32 校验码将返回负整数,因此你需要使用 sprintf() 或 printf() 的“%u”格式符来获取表示无符号 crc32 校验码的字符串。

<?php$str = crc32("Hello world.");
echo 'Without %u: '.$str."<br />";
echo 'With %u: ';
printf("%u",$str);?> 
输出:

Without %u: -1959132156With %u: 2335835140

二:string  md5 ( string str [, bool raw_output] )

Calculates the MD5 hash of str using the RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash. The hash is a 32-character hexadecimal number

If the optional raw_output is set to TRUE, then the md5 digest is instead returned in raw binary format with a length of 16. 

The optional raw_output parameter was added in PHP 5.0.0 and defaults to FALSE 

md5() 函数计算字符串的 MD5 散列。

md5() 函数使用 RSA 数据安全,包括 MD5 报文摘译算法。

如果成功,则返回所计算的 MD5 散列,如果失败,则返回 false

TRUE - 原始 16 字符二进制格式

FALSE - 默认。32 字符十六进制数

<?php
$str = 'apple';

if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {
    echo "Would you like a green or red apple?";
    exit;
}
?> 

三:string  sha1 ( string str [, bool raw_output] )

Calculates the sha1 hash of str using the US Secure Hash Algorithm 1, and returns that hash. The hash is a 40-character hexadecimal number. If the optional raw_output is set to TRUE, then the sha1 digest is instead returned in raw binary format with a length of 20. 

The optional raw_output parameter was added in PHP 5.0.0 and defaults to FALSE 

sha1() 函数计算字符串的 SHA-1 散列。

sha1() 函数使用美国 Secure Hash 算法 1

如果成功,则返回所计算的 SHA-1 散列,如果失败,则返回 false

TRUE - 原始 20 字符二进制格式

FALSE - 默认。40 字符十六进制数

<?php
$str = 'apple';
                     
if (sha1($str) === 'd0be2dc421be4fcd0172e5afceea3970e2f3d940') {
    echo "Would you like a green or red apple?";
    exit;
}
?> 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值