CakeFest 2024: The Official CakePHP Conference

openssl_pkey_get_private

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

openssl_pkey_get_private秘密鍵を取得する

説明

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

openssl_pkey_get_private()private_key をパースし、他の関数で使用できるよう準備します。

パラメータ

private_key

private_key は以下のいずれかです。

  1. file://path/to/file.pem 形式の文字列。 このファイルは、PEM エンコードされた証明書/秘密鍵である必要が あります(両方を含むことも可能です)。
  2. PEM フォーマットの秘密鍵。

passphrase

指定されたキーが(パスフレーズを用いて)暗号化されている場合は、 オプションのパラメータ passphrase を使用する必要があります。

戻り値

成功した場合に、 OpenSSLAsymmetricKey クラスのインスタンスを返します。 エラー時に false を返します。

変更履歴

バージョン 説明
8.0.0 成功した場合に、 この関数は OpenSSLAsymmetricKey クラスのインスタンスを返すようになりました。 これより前のバージョンでは、 OpenSSL key 型のリソースを返していました。
8.0.0 private_key は、 OpenSSLAsymmetricKey または OpenSSLCertificate クラスのインスタンスを受け入れるようになりました。 これより前のバージョンでは、 OpenSSL key または OpenSSL X.509 型のリソースを受け入れていました。
8.0.0 passphrase は、nullable になりました。
add a note

User Contributed Notes 2 notes

up
24
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
-26
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