static function try_decrypt_session($key, $edata)
{
$key->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$data = $key->decrypt($edata);
$sk = substr($data, 1, strlen($data) - 3);
$chk = unpack('n', substr($data, -2));
$chk = reset($chk);
$sk_chk = 0;
for ($i = 0; $i < strlen($sk); $i++) {
$sk_chk = ($sk_chk + ord($sk[$i])) % 65536;
}
if ($sk_chk != $chk) {
return NULL;
}
return array(ord($data[0]), $sk);
}