/**
* ASE加密
* @param String input需要加密的字符串∗@paramStringkey 私钥
* return String data加密结果∗/publicstaticfunctionASEencrypt(input, key) {size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
input=self::pkcs5pad(input, size);td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, ”, MCRYPT_MODE_ECB, ”);
iv=mcryptcreateiv(mcryptencgetivsize(td), MCRYPT_RAND);
mcrypt_generic_init(td,key, iv);data = mcrypt_generic(td,input);
mcrypt_generic_deinit(td);mcryptmoduleclose(td);
data=strtoupper(bin2hex(data));
return $data;
}
public static function pkcs5_pad ($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
/**
* ASE解密
* @param String $sStr 需要解密的字符串
* @param String $sKey 私钥
* return String $data解密结果
*/
public static function ASEdecrypt($sStr, $sKey) {
$decrypted= mcrypt_decrypt(
MCRYPT_RIJNDAEL_128,
$sKey,
base64_decode($sStr),
MCRYPT_MODE_ECB
);
$dec_s = strlen($decrypted);
$padding = ord($decrypted[$dec_s-1]);
$decrypted = substr($decrypted, 0, -$padding);
return $decrypted;
}