PHP常用的TRIPLE DES加密解密

/**
* TRIPLE DES加密
*
* @param unknown_type $string
*/

function  encrypt( $string){
$iv_size = mcrypt_get_iv_size(MCRYPT_3DES,MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size,MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_3DES, ‘a1b2c3’, $string, MCRYPT_MODE_ECB, $iv);
return str_replace(array(‘+’,”/”),array(‘-‘,’_’),base64_encode($crypttext));
}
/**
* TRIPLE DES解密
*
* @param unknown_type $string
*/
function parseDeviceToken($string){
$string = base64_decode(str_replace(array(‘-‘,”_”),array(‘+’,’/’),$string));
$iv_size = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypttext = mcrypt_decrypt(MCRYPT_3DES, ”a1b2c3”, $string, MCRYPT_MODE_ECB, $iv);
return trim($decrypttext);
}