2017-06-06 207 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"; 
?> 

然後,應該很容易找到問題(您可以更新此線程的錯誤)。

希望它有幫助!

相關問題