如何修复Crypt_GPG库中的'无法找到homedir'错误

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

我想使用pear / crypt_gpg库对有效负载进行加密,并且当我使用构建函数和另一个利用pear库的有效负载发送带有有效负载的请求时,出现以下错误:“无法找到homedir。请指定homedir在实例化Crypt_GPG对象时与'homedir'选项一起使用。”我需要怎么做才能解决此错误。

我对这个gpg加密/梨库非常陌生,还没有编写自己正在使用的其他库。

这里是库中实现crypt gpg的代码。

<?php
namespace Zaghadon\CoralpayPGPLaravel;
/**
 * Created by osemeodigie on 14/03/2019
 * Objective: building to scale
 *
 * Version 1.1.0
*/

//use Crypt_GPG;
require '../vendor/autoload.php';

use Crypt_GPG;

class CoralPayPGPEncryption extends Crypt_GPG
{

    const VERSION = array(0, 3, 0);

    /**
     * Used to encrypt the response message from Cgate.
     *
     * @return $output - of the encryption
     */
    public function encryptRequest($plainRequest, $keyId) {
        // add the valid public key
        $this->addEncryptKey($keyId);
        $encryptedRequest = $this->encrypt($plainRequest, false); // encrypt the message here

        // remove the message block labels (strip armored header and footer labels)
        // $unArmoredEncryptedMessage = $this->strip_armor($encryptedRequest, 'PGP MESSAGE');
        // convert the binary message to hex
        $encryptedBinMessageToHex = bin2hex($encryptedRequest);
        return $encryptedBinMessageToHex; // return the hex of the encrypted message
    }

这是我调用库的方法

use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\RequestException;
use Zaghadon\CoralpayPGPLaravel\CoralPayPGPEncryption;

class POSController extends Controller
{
    private $gpg;

    public function requestEncrypt($data)
    {
        $options_array = array();
        $this->gpg = new CoralPayPGPEncryption($options_array);

        $keyId ='UHSUHDFGASHDHBASDJGHAHSGDHASXXXXXXXXXXXHHSDHFGSJJDFSFHHDFHBV
                 JDFSJKHFSHGKJDFHSGKJGHKDFJKGHSDJFG
                 DFSGHHHHHJKKHJDSF'
        $encryptedData = $this->gpg->encryptRequest($data, $keyId);

        return $encryptedData;
    }

以及我对requestEncrpt()方法的利用

$data = json_encode($array);

            $payload = POSController::requestEncrypt($data);

            dd($payload);

我希望有效载荷的dd()输出是我的json数据对象的gpg加密的十六进制值,但它显示此“无法找到homedir。请在实例化时指定homedir与'homedir'选项一起使用Crypt_GPG对象。”错误。请帮助我,我做错任何事情???我该如何解决此问题???

我想使用pear / crypt_gpg库对有效负载进行加密,当我使用构建函数和另一个利用pear库的有效负载发送带有有效负载的请求时,出现这些错误“ ...

php pear gnupg
1个回答
0
投票

看这里,您需要将homedir传递给构造函数https://pear.php.net/manual/en/package.encryption.crypt-gpg.usage.php

© www.soinside.com 2019 - 2024. All rights reserved.