我必须通过发布请求(使用 Flash Uploader)提交用户会话 ID。项目基于 Zend 框架。
现在我不确定我的实现是否“安全”:
看法
var session = "<?= Anon_SimpleCrypt::encrypt(Zend_Session::getId(), 'SOME_KEY'?>";
控制器:
$sessionId = $_POST['SESSION_ID'];
$sessionId = Anon_SimpleCrypt::decrypt($sessionId, 'SOME_KEY');
Zend_Session::setId($sessionId);
加密/解密:
public static function encrypt($value, $encryptionKey)
{
$result = '';
$encryptionKey = $encryptionKey . self::getSalt($value);
for ($count = 0; $count < strlen($value); $count++) {
$char = substr($value, $count, 1);
$keychar = substr($encryptionKey, ($count % strlen($encryptionKey)) - 1, 1);
$char = chr(ord($char) + ord($keychar));
$result.=$char;
}
return base64_encode($result);
}
public static function decrypt($value, $encryptionKey)
{
$result = '';
$value = base64_decode($value);
$encryptionKey = $encryptionKey . self::getSalt($value);
for ($i = 0; $i < strlen($value); $i++) {
$char = substr($value, $i, 1);
$keychar = substr($encryptionKey, ($i % strlen($encryptionKey)) - 1, 1);
$char = chr(ord($char) - ord($keychar));
$result.=$char;
}
return $result;
}