【发布时间】:2016-06-07 14:32:53
【问题描述】:
我已经在 Windows 上为 PHP 7 安装了 libsodium,并且正在使用 PHPStorm 开发我的项目。我还安装了来自 Paragonie 的 Halite,如果未正确安装 libsodium 扩展,它甚至无法安装。 IDE 还会找到使用的函数,并在单击变量等时打开 libsodium 的拟合文件。
但不幸的是,在我的设置中,我收到以下错误:
Uncaught Error: Undefined constant 'Sodium\CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE' in C:\Server\nginx-1.11.1\html\mywebsite\vendor\paragonie\halite\src\KeyFactory.php:344
我的 index.php 文件如下所示:
<?php
require_once 'vendor/autoload.php';
spl_autoload_register(function ($class) {
require_once $class . '.php';
});
$router = new AltoRouter();
$router->setBasePath('/' . basename(__DIR__));
require_once 'config/routes.php';
$match = $router->match();
$GLOBALS['db'] = new \config\database(true, null);
try
{
if ($match) {
$routeController = new Modules\Core\RouteController($match);
echo $routeController->bootstrap();
}
}
catch (Exception $ex)
{
//@todo log every Exception
}
我还使用 Jquery 提交我的表单,这会成功执行以下函数(未找到 libsodium 函数/变量):
public function hash($password)
{
$this->setEncryptionKey();
return Password::hash(
$password, // string
$this->encryption_key // \ParagonIE\Halite\Symmetric\EncryptionKey
);
}
public function check($stored_hash, $password)
{
try {
if (Password::verify(
$password, // string
$stored_hash,
$this->encryption_key
)) {
return true;
}
} catch (\ParagonIE\Halite\Alerts\InvalidMessage $ex) {
// Handle an invalid message here. This usually means tampered ciphertext.
throw new \Exception($ex);
}
}
我已经将php_libsodium.dll 安装在扩展目录中,并将libsodium.dll 放在php 服务器的目录中。只是为了尝试,我稍后也将它放在 system32 目录和 Syswow64 目录中 - 两者都没有改变任何东西。
我刚刚用 composer 安装了 paragonie 的 halite 库,但不幸的是,使用它比我想象的要难。我也尝试在没有 Halite 的情况下使用 libsodium 扩展,但这会导致类似的错误,即找不到所需的类、常量和函数等。
我也尝试过更改我的自动加载器,但奇怪的是,IDE 可以毫无问题地找到所有内容,但在浏览器中执行脚本却没有。
【问题讨论】:
-
1) 您是否启用 php.ini 中的扩展程序以及 2) 您是否重新启动了 Web 服务器?
-
是对两者。我只是想了一下:可能是版本问题,因为我安装了 libsodium 的 1.0.6 版本,但也存在 1.0.10 版本。我没有自己编译它,而是使用了 Windows 的预编译 dll 文件。我还用 phpinfo() 检查了它,它说 libsodium 支持已启用,但库版本仅为 1.0.5,而编译版本为 1.0.6
标签: php php-extension libsodium