PHP致命错误。未捕获错误。没有找到'Elliptic\EC'类。

问题描述 投票:0回答:1

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

我已经使用了这个库。https:/github.comsimplitoelliptic-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 Composer 1.6.3 从这个教程。https:/linuxize.composthow-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

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

php private-key public-key elliptic-curve generate
1个回答
0
投票

试着把文件包含在类中,如果存在的话 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";
© www.soinside.com 2019 - 2024. All rights reserved.