you can get public key using openssl_pkey_get_details(resource $key ) function:
<?php
$pub_key = openssl_pkey_get_public(file_get_contents('./cert.crt'));
$keyData = openssl_pkey_get_details($pub_key);
fule_put_contents('./key.pub', $keyData['key']);
?>
openssl_pkey_export
(PHP 4 >= 4.2.0, PHP 5)
openssl_pkey_export — エクスポート可能な形式で、キーを文字列に取得する
説明
bool openssl_pkey_export
( mixed $key
, string &$out
[, string $passphrase
[, array $configargs
]] )
openssl_pkey_export() は、 key を PEM エンコードした文字列として取得し、 out (参照渡し)に格納します。
注意: この関数を正しく動作させるには、正しい形式の openssl.cnf をインストールしておく必要があります。 詳細な情報は、インストールについてのセクション を参照ください。
パラメータ
- key
-
- out
-
- passphrase
-
オプションで passphrase を使用してキーを保護することが可能です。
- configargs
-
configargs により openssl 設定ファイルの設定を 追加したり上書きしたりすることで、エクスポート処理の詳細設定が可能です。 configargs についての詳細な情報は openssl_csr_new() を参照ください。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
openssl_pkey_export
08-May-2007 04:31
robbat2 at gentoo dot org
10-Aug-2004 03:47
10-Aug-2004 03:47
Warning, this function is NOT capable of exporting PEM-encoded public keys. It can only export private keys.
