Please note that "file://path/to/file.pem" in documentation means file protocol + file path. In UNIX like OS, that is something like file:///rsa_private_key.pem. There is THREE slashes in the path string, not TWO.
openssl_pkey_get_private
(PHP 4 >= 4.2.0, PHP 5)
openssl_pkey_get_private — Lit une clé privée
Description
openssl_pkey_get_private() analyse la clé
key et la prépare pour être utilisée
par d'autres fonctions.
Liste de paramètres
-
key -
keypeut être l'une des valeurs suivantes :- une chaîne au format file://path/to/file.pem. Le fichier ainsi désigné doit contenir une clé privée ou un certificat au format PEM (éventuellement les deux).
- Une clé privée au format PEM.
-
passphrase -
Le paramètre optionnel
passphrasedoit être utilisé si la clé spécifiée est chiffrée (protégée par un mot de passe).
Valeurs de retour
Retourne une ressource positive représentant une clé en cas de succès, ou
FALSE si une erreur survient.
joelhy ¶
2 years ago
justin at gripwire dot com ¶
5 years ago
At least as of PHP 5.2.5, this function's prototype matches what is given on this page (i.e. it does not require an array for its two parameters).
Joel Barker ¶
7 years ago
Note that the important part of meint's post is that there is a SINGLE argument: an ARRAY of two elements. In other words, the correct prototype of the function is
resource openssl_pkey_get_private ( array params )
where params = array( 0 => $key, 1 => $passphrase)
Thanks, meint, you made my day!
meint dot post at bigfoot dot com ¶
10 years ago
Trying for hours to get openssl_pkey_get_private to load my private key (no problems with openssl_pkey_get_public) I found that the following loaded the private key correctly:
$passphrase="test";
$priv_key_file_name = ("./private.pem");
if (openssl_pkey_get_private(array("file://$priv_key_file_name", $passphrase)))
{
print "\nPrivate Key OK\n\n";
} else {
print "\nPrivate key NOT OK\n\n";
}
