简体   繁体   中英

openssl_pkey_get_details cause internal server error

I make some code to generate public and private code. It was working ok on one machine, but on other server it is causing "Internal Server Error".

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);
}

Sadly I didn't find any information about this error in any log. I only find that it is caused by this line:

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

Key is generated properly - when I deleted openssl_pkey_get_details, private key was saved in file.

Any ideas what is wrong, or other method to get public key?

Sadly I didn't find any information about this error in any log.

You can use openssl_error_string() to find out what is openssl_pkey_new() returning, you should see a false or any other OpenSSL error (from here ). Like:

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

Then it should be easy to find the problem (you can update this thread with the error).

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM