PHP DES 算法

通信中用到PHP的DES加密算法:

//DES加密
function des_encode($string, $key)
	{
		$size	= mcrypt_get_block_size('des','ecb');
		$pad	= $size - (strlen($string) % $size);
		$string	.= str_repeat(chr($pad), $pad);
		$td		= mcrypt_module_open('des', '', 'ecb', '');
		$iv		= mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
		@mcrypt_generic_init($td, $key, $iv);
		$data	= mcrypt_generic($td, $string);
		mcrypt_generic_deinit($td);
		mcrypt_module_close($td);
		return bin2hex($data);
	}
 

 

 

你可能感兴趣的:(php DES算法)