Can PHP OpenSSL generate private/public key/certificate pairs?

后端 未结 2 1983
时光取名叫无心
时光取名叫无心 2020-12-19 10:11

I wonder if PHP\'s OpenSSL extension can be used to generate private/public key/certificate pairs?

2条回答
  •  天命终不由人
    2020-12-19 10:47

    Sure, use openssl_pkey_new:

    $privateKey = openssl_pkey_new(array('private_key_bits' => 2048));
    $details = openssl_pkey_get_details($privateKey);
    $publicKey = $details['key'];
    

    You can export the keys with openssl_pkey_export or openssl_pkey_export_to_file.

提交回复
热议问题