首页 > 解决方案 > openssl_pkey_new 返回空白且没有错误消息

问题描述

我有以下代码:

    $config = array(
    "digest_alg" => "sha512",
    "private_key_bits" => $size,
    "private_key_type" => OPENSSL_KEYTYPE_RSA,
    "config" => "/home/user/openssl/ssl/openssl.cnf"
);  
    // Create the private and public key
    echo "hi";
    debug_to_console($config);
    $res = openssl_pkey_new($config);
    debug_to_console($res);
    while ($msg = openssl_error_string()){
            echo $msg . "<br />\n";
    }


    // Extract the private key from $res to $privKey
    openssl_pkey_export($res, $privKey);
    // Extract the public key from $res to $pubKey
    $pubKey = openssl_pkey_get_details($res);
    $pubKey = $pubKey["key"];

    echo "hello";
    var_dump($pubKey);
    var_dump($privKey);
    return $pubKey;

出于某种原因,openssl_pkey_new根本不返回任何东西 - 甚至没有错误。

“hi”打印出来,并将debug_to_console值输出到控制台。$config打印得很好,但该$res行之后的任何内容都是空白的。整个页面只是“嗨”,没有别的。

我很困惑它如何不起作用并且没有错误消息..有人有什么想法吗?

编辑:在archlinux上,PHP 5.5.9

标签: php

解决方案


推荐阅读