5
如何創建一個新的密鑰對並將它們保存在文件中?我猜是OpenSSL。我有Windows 7和Xampp,它在APache目錄中有OpenSSL(儘管我在openssl_pkey_new()方面有一些問題(請參閱Why does openssl_pkey_new() fail?)如何創建新的密鑰對並將其保存在文件中?
無論如何,一旦我配置了OpenSSL,代碼看起來像創建新的密鑰對,並將它們保存在文件中
如何創建一個新的密鑰對並將它們保存在文件中?我猜是OpenSSL。我有Windows 7和Xampp,它在APache目錄中有OpenSSL(儘管我在openssl_pkey_new()方面有一些問題(請參閱Why does openssl_pkey_new() fail?)如何創建新的密鑰對並將其保存在文件中?
無論如何,一旦我配置了OpenSSL,代碼看起來像創建新的密鑰對,並將它們保存在文件中
要生成密鑰對:
<?php
/* Create the private and public key */
$res = openssl_pkey_new();
/* Extract the private key from $res to $privKey */
openssl_pkey_export($res, $privKey);
/* Extract the public key from $res to $pubKey */
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey["key"];
?>
要保存的關鍵目標文件:
file_put_contents($file, $key);