首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP致命错误:未捕获错误:找不到'Elliptic\EC‘类

PHP致命错误:未捕获错误:找不到'Elliptic\EC‘类
EN

Stack Overflow用户
提问于 2020-05-02 05:37:41
回答 1查看 244关注 0票数 0

我想在PHP中使用椭圆曲线加密生成私钥/公钥。

我使用过这个库:https://github.com/simplito/elliptic-php

我的代码:

代码语言:javascript
复制
<?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";

但它向我显示了这个错误:

代码语言:javascript
复制
PHP Fatal error:  Uncaught Error: Class 'Elliptic\EC' not found in /home/istabraq/bctest/test1/keygenerator.php:6

我已经通过本教程安装了composer Composer 1.6.3https://linuxize.com/post/how-to-install-and-use-composer-on-ubuntu-18-04/

然后安装了sudo apt-get install php7.2-gmpcomposer require simplito/elliptic-php,最后安装了composer require simplito/bn-php,但最后的命令行显示了以下输出:

代码语言:javascript
复制
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

我错过了什么请帮帮我?我搜索问题,但没有教程。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-02 06:22:49

尝试将文件包含在类中,或者如果现有的vendor/autoload.php包含它,例如:

代码语言:javascript
复制
<?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";
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61551198

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档