har*_*ing 2 php php-extension libsodium
我在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
Run Code Online (Sandbox Code Playgroud)
我的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
}
Run Code Online (Sandbox Code Playgroud)
我也用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);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经在扩展目录中安装了php_libsodium.dll,并将libsodium.dll放入php服务器的目录中.只是为了尝试我稍后也将它放在system32目录和Syswow64目录中 - 两者都没有改变任何东西.
我刚用paragonie和作曲家安装了halite库,但遗憾的是使用它比我想象的要难.我也尝试使用没有Halite的libsodium扩展,但是导致类似的错误,找不到所需的类,常量和函数等.
我也试图改变我的自动加载磁带机,但奇怪的反正是IDE耳目一新没有问题,但执行脚本的浏览器只是不.
要使用Halite 2.x,您需要:
验证这是否已设置的简单方法是:
<?php
use \ParagonIE\Halite\Halite;
var_dump(Halite::isLibsodiumSetupCorrectly());
Run Code Online (Sandbox Code Playgroud)
如果您想了解更多关于失败的具体信息,请改为运行:
<?php
use \ParagonIE\Halite\Halite;
// TRUE enables verbose output:
Halite::isLibsodiumSetupCorrectly(true);
Run Code Online (Sandbox Code Playgroud)
最有可能的是,您需要卸载/重新安装针对较新版本的共享库编译的PHP扩展.
现在正在讨论针对PHP 7.1的RFC,如果被接受,将来会使这种情况变得轻松.RFC多年后通过了; libsodium将使用PHP 7.2.