openssl_pkey_get_private

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

openssl_pkey_get_privateLit une clé privée

Description

openssl_pkey_get_private(OpenSSLAsymmetricKey|OpenSSLCertificate|array|string $private_key, ?string $passphrase = null): OpenSSLAsymmetricKey|false

openssl_pkey_get_private() analyse la clé private_key et la prépare pour être utilisée par d'autres fonctions.

Liste de paramètres

private_key

private_key peut être l'une des valeurs suivantes :

  1. 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).
  2. Une clé privée au format PEM.

passphrase

Le paramètre optionnel passphrase doit être utilisé si la clé spécifiée est chiffrée (protégée par un mot de passe).

Valeurs de retour

Retourne une instance de OpenSSLAsymmetricKey cas de succès, ou false si une erreur survient.

Historique

Version Description
8.0.0 En cas de succès, cette fonction retourne désormais une instance de OpenSSLAsymmetricKey ; auparavant, une ressource de type OpenSSL key était retourné.
8.0.0 private_key accepte désormais une instance de OpenSSLAsymmetricKey ou OpenSSLCertificate ; auparavant, une ressource de type OpenSSL key ou OpenSSL X.509 était acceptée.
8.0.0 passphrase est désormais nullable.
add a note add a note

User Contributed Notes 2 notes

up
32
kristof1 at mailbox dot hu
9 years ago
It's actually "file://key.pem" when you want to give a relative path using unix systems. It will be three '/' in case of absolute path (e.g "file:///home/username/..."). But this path consists of two '/' originated from "file://" and one '/' from the fact that home is a subfolder of the unix filesystem's root directory ("/home/username/..."). This two part will be concatenated and you will get three '/' characters following each other.

So you only have to concatenate "file://" with an existing path string in every case.
up
1
pablo dot siciliano at gmail dot com
3 years ago
Hi.

If this function not work with pathname try with a file_get_contents of a key file.
To Top