openssl_free_key期望参数1是资源

时间:2013-07-18 14:29:56

标签: php php-openssl

我有这段代码:

openssl_pkcs12_read($p12buf, $p12cert, $decPass);
openssl_pkey_export($p12cert['pkey'], $pemkey); 
openssl_sign($toSign, $signature, $pemkey, OPENSSL_ALGO_SHA1);
openssl_free_key($pemkey);

我收到了这个警告:

Warning (2): openssl_free_key() expects parameter 1 to be resource, string given

我怎样摆脱它或我做错了什么?

1 个答案:

答案 0 :(得分:1)

openssl_free_key需要openssl_pkey_get_privateopenssl_pkey_get_public

的结果(资源)
$key = openssl_pkey_get_private($keyFile, $passphrase);
openssl_free_key($key);