openssl_pkey_get_details导致内部服务器错误

时间:2017-06-06 12:07:37

标签: php apache php-openssl

我制作了一些代码来生成公共和私有代码。它在一台机器上工作正常,但在其他服务器上却导致了“内部服务器错误”#34;。

private function keyGen()   
{
    if(is_file($this::pubK_path) )
        exec("rm ".$this::pubK_path);
    if(is_file($this::privK_path) )
        exec("rm ".$this::privK_path);

    $config = array(
        "digest_alg" => "sha512",
        "private_key_bits" => 512,
        "private_key_type" => OPENSSL_KEYTYPE_RSA
    );

    // Create the private and public key
    $this->key = openssl_pkey_new($config);

    $pubkey=openssl_pkey_get_details($this->key);
    $this->pubkey=$pubkey["key"];

    $privK=null;
    openssl_pkey_export($this->key, $privK,$this->pass);
    file_put_contents($this::privK_path, $privK);
    file_put_contents($this::pubK_path, $this->pubkey);
}

可悲的是,我没有在任何日志中找到有关此错误的任何信息。我只发现它是由这一行引起的:

$pubkey=openssl_pkey_get_details($this->key);

正确生成密钥 - 当我删除openssl_pkey_get_details时,私钥已保存在文件中。

任何想法有什么不妥,或其他获取公钥的方法?

1 个答案:

答案 0 :(得分:0)

  

遗憾的是,我没有在任何日志中找到有关此错误的任何信息。

您可以使用openssl_error_string()找出openssl_pkey_new()返回的内容,您应该看到false或任何其他OpenSSL错误(来自here)。像:

<?php
// lets assume you just called an openssl function that failed
while ($msg = openssl_error_string())
    echo $msg . "<br />\n";
?>

然后应该很容易找到问题(您可以使用错误更新此线程)。

希望它有所帮助!

相关问题