函式名稱:openssl_pkey_free()
適用版本:PHP 4 >= 4.2.0, PHP 5, PHP 7
函式描述:openssl_pkey_free() 用於釋放之前透過 openssl_pkey_new() 建立的私鑰資源。
語法:bool openssl_pkey_free ( resource $key )
引數:
- key:一個私鑰資源,透過 openssl_pkey_new() 建立。
返回值:成功時返回true,失敗時返回false。
示例:
// 建立一個私鑰資源
$privateKey = openssl_pkey_new();
// 使用私鑰資源進行一些操作...
// 釋放私鑰資源
openssl_pkey_free($privateKey);
在上述示例中,我們首先使用openssl_pkey_new()函式建立了一個私鑰資源$privateKey。然後,我們可以使用此私鑰資源進行一些加密、解密或簽名等操作。最後,使用openssl_pkey_free()函式釋放私鑰資源,以避免資源洩露和記憶體洩漏。
請注意,釋放私鑰資源是一個良好的程式設計實踐,特別是在處理大量金鑰的情況下。