php - PHP 致命错误:未捕获的错误:找不到类“Elliptic\EC”
问题描述
我想在 PHP 中使用椭圆曲线加密生成私钥/公钥。
我用过这个库:https ://github.com/simplito/elliptic-php
我的代码:
<?php
use Elliptic\EC;
// Create and initialize EC context
// (better do it once and reuse it)
$ec = new EC('secp256k1');
// Generate keys
$key = $ec->genKeyPair();
$publicKey = $key->getPublic('hex');
$privateKey = $key->getPrivate('hex');
// Print the keys to the console
echo "The address1 is {$publicKey}. \r\n";
echo "The address1 is {$privateKey}. \r\n";
但它向我显示了这个错误:
PHP Fatal error: Uncaught Error: Class 'Elliptic\EC' not found in /home/istabraq/bctest/test1/keygenerator.php:6
我已经安装Composer 1.6.3
了本教程中的作曲家:
https ://linuxize.com/post/how-to-install-and-use-composer-on-ubuntu-18-04/
然后安装sudo apt-get install php7.2-gmp
并安装 composer require simplito/elliptic-php
,最后安装composer require simplito/bn-php
,但最后一个命令行向我显示了这个输出:
Using version ^1.1 for simplito/bn-php
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
我错过了什么请帮忙?我搜索问题但没有教程。
解决方案
尝试包含带有类的文件,或者如果存在vendor/autoload.php
包含它,例如:
<?php
include 'path/vendor/autoload.php'; //or 'path/file/EC.php'
use Elliptic\EC;
// Create and initialize EC context
// (better do it once and reuse it)
$ec = new EC('secp256k1');
// Generate keys
$key = $ec->genKeyPair();
$publicKey = $key->getPublic('hex');
$privateKey = $key->getPrivate('hex');
// Print the keys to the console
echo "The address1 is {$publicKey}. \r\n";
echo "The address1 is {$privateKey}. \r\n";
推荐阅读
- php - Laravel w/ Docker - 生产安全吗?
- javascript - 全日历。从外部列表中删除拖动的事件
- python - 如何计算 django 中 id 低于当前 id 的对象
- python - 如何保证dict的处理顺序?
- sql - 根据多行采购订单行详细信息汇总所有发票
- docker - 如何在非 root 运行的容器中安装新软件包?
- twig - 三元运算符不会返回 HTML
- javascript - 无法在网页上查看 JS API 响应
- python - 在 Wagtail 中实现文章和页面模型之间的一对多
- gremlin - 使用 JanusGraph 的 ReferenceEdge 序列化错误