PHP 常见加密算法

  • hash_file() - Generate a hash value using the contents of a given file
  • hash_hmac() - Generate a keyed hash value using the HMAC method
  • hash_init() - Initialize an incremental hashing context
  • md5() - 计算字符串的 MD5 散列值
  • sha1() - 计算字符串的 sha1 散列值

 

PHP 各种加密算法

<?php 
	$data = "www.mimvp.com"; 
	
	echo 'data : ' . $data . "</br></br>";
	
	echo '<table>';
	echo '<tr><td>algrithm</td><td>strlen</td><td>string</td></tr>';
	
	// md5
	$v_md5 = md5($data);
	echo '<tr><td>self_md5</td><td>' . strlen($v_md5) . '</td><td>' . $v_md5 . '</td></tr>';

	$v_md5 = md5($data, true);
	echo '<tr><td>self_md5_16</td><td>' . strlen($v_md5) . '</td><td>' . $v_md5 . '</td></tr>';
	
	// sha1
	$v_sha1 = sha1($data);
	echo '<tr><td>self_sha1</td><td>' . strlen($v_sha1) . '</td><td>' . $v_sha1 . '</td></tr>';

	$v_sha1 = sha1($data, true);
	echo '<tr><td>self_sha1_20</td><td>' . strlen($v_sha1) . '</td><td>' . $v_sha1 . '</td></tr>';
	
	echo '<tr><td colspan="3"></td></tr>';
	
	// all algrithm
	foreach (hash_algos() as $ha) { 
	    $r = hash($ha, $data, false); 
	    echo "<tr>";
	    echo "<td width='100'>" . $ha . "</td>";
	    echo "<td width='50'>" . strlen($r) . "</td>";
	    echo "<td width='600'>" . $r . "</td>";
	    echo "</tr>";
	} 
	
	echo "</table>";
?> 

运行结果:

data : www.mimvp.com

algrithm	strlen	string
self_md5	32	52c06085c45297325433e0c75b140565
self_md5_16	16	RÀ`…ÄR—2T3àÇ[e
self_sha1	40	2f465e03a1f69f5cfe1a92b3a946e689866b1486
self_sha1_20	20	/F^¡öŸ\þ’³©F扆k†
md2	32	348481327946c43ab8db9d688bde828e
md4	32	4968e754cea66e16b8a3eaf994a4c1bc
md5	32	52c06085c45297325433e0c75b140565
sha1	40	2f465e03a1f69f5cfe1a92b3a946e689866b1486
sha224	56	f83897ed9cb82b5699ba52806675af3083990ff347a06e2004764fe8
sha256	64	2ad69e143eedfb65ea80f46be92b707373f07183afd5cc5c578248a9cdaedb61
sha384	96	e630c54a524b1d80c0990c3e48f5f5f4dac7d0f0497aef9990cffe9ea657e436f1469c58e9909f016552636217338b21
sha512	128	0089bab01dadfa60e0150ca57fa15216a78ed9bb0a0d41521a136e02e2023e4a12368f9b50153c3bc3146fda5d9d370d5464c707e3f0cf4bec8ac51539dfd658
ripemd128	32	1265ab26b4820351a548647c5290dd95
ripemd160	40	f77ad8ffeb5f210b94c60800caaabcc9a0223c7f
ripemd256	64	94618133e374f41149d82e811106de4719c1a54a6e48180084143f74d9d49764
ripemd320	80	cd8d89cb4d0444e6841b0c1d238ba9437d04be75d4fb1c22a484fb3881cb40bf7daaffa1964b93cd
whirlpool	128	7ebc5e7ba6733a9e42cf28c43e9a4cafe1984a3415e3979c3e41aec27ef81cbfaffe968db1a3dfc9d8813a85f3b714ddeb07ba9110d748458c49b78134261eef
tiger128,3	32	ef4553cb20881b72c12e80a241e2e822
tiger160,3	40	ef4553cb20881b72c12e80a241e2e822b9702400
tiger192,3	48	ef4553cb20881b72c12e80a241e2e822b9702400e4d5a496
tiger128,4	32	998c4b1228ff8bd8d8c780b70818368b
tiger160,4	40	998c4b1228ff8bd8d8c780b70818368b5a1b459e
tiger192,4	48	998c4b1228ff8bd8d8c780b70818368b5a1b459e47ecffd0
snefru	64	ffa74b37aebf0dad2a6d52b6a75d6c2e95d3fc533922396f2afd4771768f4486
snefru256	64	ffa74b37aebf0dad2a6d52b6a75d6c2e95d3fc533922396f2afd4771768f4486
gost	64	c8ac059fa5e6cf71663e94bba50a1401a67e93f82dafa6636078cca956d3981e
adler32	8	24cd052a
crc32	8	bef4d7a3
crc32b	8	69f6199a
fnv132	8	799b26dc
fnv164	16	13fa3f9ebce38a3c
joaat	8	0f769656
haval128,3	32	d52a6ce49d3a78e1ed05d20bbf08feae
haval160,3	40	3666c0122a13e1b4bfad048dbe8b7fbdfecc47b8
haval192,3	48	afbe47e4f366d9bdf67634231b30ecb7336be930d5e11405
haval224,3	56	362908f2394493cb1624a24174d1e83e70c761508ac65b1f4ebca08d
haval256,3	64	2700747ac4cc725ca0f457e243e280355b6e3c7711bafb3fc3817efb094c88a0
haval128,4	32	8e8a0da03c8faca9cbde27d7f932e523
haval160,4	40	8e860279dac97609499c2fb93d55f40ca3537170
haval192,4	48	4080372f1198b019f577ad449ded45552bebf88282c274a4
haval224,4	56	ad510eec3c67701c312d0fd36a7437f2bc119d1fafcbce7ca22026c3
haval256,4	64	c150c460ef0d3254e41c1bbbf5f2b597f6aca90e08002bec8cea4df28f4fcf50
haval128,5	32	ca3b0b9e42dec05b0a53c68bd447865f
haval160,5	40	f45e9a76d7eb7007a0e4215f6e33c538fbe54c03
haval192,5	48	beba539c0fd53899bf7e51320783f8abf026edf1f16aceff
haval224,5	56	905b0b946980bb4dff4c585ec806ae86cc53b42526f8dfee7327f8bc
haval256,5	64	acc8ad0e886dcd81a0290a02e47c56f74996e1ce4c76721fd487b3f8a3c2412d

 

 

参考推荐

Python 常用加密算法 base64, md5, sha1

PHP、Python、Java、C#、Javascript 运用AES加密解密

URL短网址生成的简单示例

URL短网址生成算法原理