函式名稱:openssl_free_key()
適用版本:PHP 4 >= 4.0.4, PHP 5, PHP 7
函式描述:openssl_free_key() 函式釋放一個之前透過 openssl_pkey_new() 或 openssl_pkey_get_private() 建立或獲取的私鑰資源。
用法:
bool openssl_free_key ( resource $key )
引數:
- key:一個之前透過 openssl_pkey_new() 或 openssl_pkey_get_private() 建立或獲取的私鑰資源。
返回值:
成功時返回 true,失敗時返回 false。
示例:
// 生成一個新的私鑰
$config = array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
);
$privateKey = openssl_pkey_new($config);
// 使用私鑰進行加密或簽名等操作
// 釋放私鑰資源
openssl_free_key($privateKey);
在示例中,我們首先使用 openssl_pkey_new() 函式生成一個新的私鑰資源 $privateKey,並使用該私鑰進行加密或簽名等操作。當不再需要該私鑰時,可以使用 openssl_free_key() 函式釋放該私鑰資源,以便釋放記憶體和其他資源。