PHP Velho Oeste 2024

openssl_csr_export

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

openssl_csr_exportCSR を文字列としてエクスポートする

説明

openssl_csr_export(OpenSSLCertificateSigningRequest|string $csr, string &$output, bool $no_text = true): bool

openssl_csr_export() は、Certificate Signing Request csr を受け取り、 それを outputPEMフォーマット として保存します。 このパラメータは参照で渡されます。

パラメータ

csr

使用できる値の一覧は CSR パラメータ を参照ください。

output

成功した場合、この文字列には PEMエンコードされた CSR が入っています。

no_text

オプションのパラメータ notext を設定すると、出力内容の冗長性が変化します。false を指定すると、 人間が読むための追加情報が出力に含まれるようになります。 notext のデフォルト値は true です。

戻り値

成功した場合に true を、失敗した場合に false を返します。

変更履歴

バージョン 説明
8.0.0 csr は、 OpenSSLCertificateSigningRequest クラスのインスタンスを受け入れるようになりました。 これより前のバージョンでは、 OpenSSL X.509 CSR 型のリソースを受け入れていました。

例1 openssl_csr_export() の例

<?php
$subject
= array(
"commonName" => "example.com",
);
$private_key = openssl_pkey_new(array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
));
$configargs = array(
'digest_alg' => 'sha256WithRSAEncryption'
);
$csr = openssl_csr_new($subject, $private_key, $configargs);
openssl_csr_export($csr, $csr_string);
echo
$csr_string;
?>

参考

add a note add a note

User Contributed Notes 1 note

up
2
carlos AT wfmh DOT org DOT pl
21 years ago
Here you come with the example of how to use this function.

if( $csr = openssl_csr_new( array(
     "countryName"=>"PL",
     "stateOrProvinceName" => "blah",
     "organizationName" => "company ltd",
     "commonName"=>"foo.bar.com",
     "Email"=>"blah@foo.bar.com"), $privkey )
                  )
   {
   openssl_csr_export_to_file( $csr, "out.csr");
   }
else
   {
   printf("failed\n");
   }

Keep in mind that keys are case sensitive (i.e. give "email" instead of "Email" and you get warning). Also remember it's important to keep the order of the arguments in array. Move the "Email" above commonName and check what you get (in case you don't know how: "openssl req -noout -text -in out.csr").

It also happened to me me I got segfault when order was rubbish (afair Email after countryName, or plenty Email's here and there), so be awared.
To Top