【问题标题】:openssl_seal fails error:0E06D06C:configuration file routines:NCONF_get_string:no valueopenssl_seal 失败错误:0E06D06C:配置文件例程:NCONF_get_string:无值
【发布时间】:2020-08-21 07:53:10
【问题描述】:

我正在尝试密封/打开文件。加密失败,产生如下错误。

error:0E06D06C:configuration file routines:NCONF_get_string:no value

这是一个可以重现问题的代码示例

    // Generate key pair and keep them safe...
    $key = openssl_pkey_new([
        'private_key_bits' => 4096,
        'private_key_type' => OPENSSL_KEYTYPE_EC,
        'curve_name' => 'prime256v1',
    ]);

    $privKey = null;
    openssl_pkey_export($key, $privKey);
    $pubKeyDetails = openssl_pkey_get_details($key);
    $pubKey = $pubKeyDetails['key'];
    openssl_free_key($key);

    // Load the pubkey to encrypt
    $key = openssl_pkey_get_public($pubKey);
    $data = file_get_contents('of-some-pretty-large-file');


    // ----- This here fails -----
    if (openssl_seal($data, $sealed, $eKeys, [$key]) === false) {
        echo "Encryption failed\n";
        echo openssl_error_string() . "\n";
        exit;
    }
    openssl_free_key($key);

    $key = openssl_pkey_get_private($privKey);
    if (openssl_open($sealed, $decryptedData, $eKeys[0], $key)) {
        echo ($decryptedData === $data ? "Matched\n" : "Trash\n");
    }
    openssl_free_key($key);

【问题讨论】:

    标签: php-openssl


    【解决方案1】:

    错误信息

    error:0E06D06C:configuration file routines:NCONF_get_string:no value
    

    不是由openssl_seal引起的,而是由openssl_pkey_new引起的。这不会影响功能,即成功生成密钥,请参阅herehere。这也适用于发布的代码,它生成一个 SEC1 格式的私有 EC 密钥和一个 X.509 格式的公钥。

    PHP 方法 openssl_seal 基于 OpenSSL 函数 EVP_SealInitEVP_SealUpdateEVP_SealFinalhere。在corresponding OpenSSL 文档中,Notes-部分中描述了以下内容:

    公钥必须是 RSA,因为它是唯一支持密钥传输的 OpenSSL 公钥算法。

    这意味着openssl_seal 仅适用于 RSA 或 RSA 密钥。如果发布的代码中使用了以下内容:

    $key = openssl_pkey_new([
        'private_key_bits' => 4096,
        'private_key_type' =>  OPENSSL_KEYTYPE_RSA
    ]);
    

    解密和加密按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-21
      • 2018-03-22
      • 2018-04-08
      • 2017-02-23
      • 2013-10-01
      • 1970-01-01
      • 2021-04-28
      • 2019-02-04
      相关资源
      最近更新 更多