2017-06-06 224 views
0

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

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,私钥保存在文件中。

任何想法什么是错的,或其他方法来获得公钥?

+0

您是否尝试过更多?你有没有发现'openssl_error_string()'的错误? –

回答

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"; 
?> 

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

希望它有帮助!

相关问题