OpenSSL 関数
目次
- openssl_cipher_iv_length — 初期化ベクトル iv の長さを取得する
- openssl_cipher_key_length — 暗号鍵の長さを取得する
- openssl_cms_decrypt — CMS メッセージを復号化する
- openssl_cms_encrypt — CMS メッセージを暗号化する
- openssl_cms_read — CMS ファイルを、PEM証明書の配列にエクスポートする
- openssl_cms_sign — ファイルに署名する
- openssl_cms_verify — CMS の署名を検証する
- openssl_csr_export — CSR を文字列としてエクスポートする
- openssl_csr_export_to_file — CSR をファイルにエクスポートする
- openssl_csr_get_public_key — CSR の公開鍵を返す
- openssl_csr_get_subject — CSR の subject を返す
- openssl_csr_new — CSR を作成する
- openssl_csr_sign — CSR に他の証明書(あるいは自分自身)で署名して証明書を作成する
- openssl_decrypt — データを復号する
- openssl_dh_compute_key — ローカルのDH秘密鍵とリモート側のDH公開鍵を使い、共有シークレットを計算する
- openssl_digest — ダイジェストを計算する
- openssl_encrypt — データを暗号化する
- openssl_error_string — OpenSSL エラーメッセージを返す
- openssl_free_key — キーリソースを開放する
- openssl_get_cert_locations — 有効な証明書の格納場所を検索する
- openssl_get_cipher_methods — 利用可能な暗号メソッドを取得
- openssl_get_curve_names — ECC で利用可能な楕円曲線の名前を取得する
- openssl_get_md_methods — 利用可能なダイジェスト・メソッドを取得
- openssl_get_privatekey — openssl_pkey_get_private のエイリアス
- openssl_get_publickey — openssl_pkey_get_public のエイリアス
- openssl_open — シール(暗号化)されたデータをオープン(復号)する
- openssl_pbkdf2 — PKCS5 v2 の PBKDF2 文字列を生成する
- openssl_pkcs12_export — PKCS#12 互換の証明書保存ファイルを変数にエクスポートする
- openssl_pkcs12_export_to_file — PKCS#12 互換の証明書保存ファイルをエクスポートする
- openssl_pkcs12_read — PKCS#12 認証ストアをパースして配列形式にする
- openssl_pkcs7_decrypt — S/MIME 暗号化されたメッセージを復号する
- openssl_pkcs7_encrypt — S/MIME メッセージを暗号化する
- openssl_pkcs7_read — PKCS7 ファイルを PEM証明書 の配列にエクスポートする
- openssl_pkcs7_sign — S/MIME メッセージに署名する
- openssl_pkcs7_verify — S/MIME で署名されたメッセージの署名を検証する
- openssl_pkey_derive — リモートとローカルの DH/ECDH鍵 の公開値のための、共有シークレットを計算する
- openssl_pkey_export — エクスポート可能な形式で、キーを文字列に取得する
- openssl_pkey_export_to_file — エクスポート可能な形式で、キーをファイルに取得する
- openssl_pkey_free — 秘密鍵を開放する
- openssl_pkey_get_details — キーの詳細の配列を返す
- openssl_pkey_get_private — 秘密鍵を取得する
- openssl_pkey_get_public — 証明書から公開鍵を抽出し、使用できるようにする
- openssl_pkey_new — 新規に秘密鍵を生成する
- openssl_private_decrypt — 秘密鍵でデータを復号する
- openssl_private_encrypt — 秘密鍵でデータを暗号化する
- openssl_public_decrypt — 公開鍵でデータを復号する
- openssl_public_encrypt — 公開鍵でデータを暗号化する
- openssl_random_pseudo_bytes — 疑似ランダムなバイト文字列を生成する
- openssl_seal — データをシール(暗号化)する
- openssl_sign — 署名を生成する
- openssl_spki_export — 署名済みの公開鍵とチャレンジから、有効なPEMフォーマットの公開鍵をエクスポートする
- openssl_spki_export_challenge — 署名済みの公開鍵とチャレンジに関連するチャレンジをエクスポートする
- openssl_spki_new — 署名された公開鍵とチャレンジを新規に作成する
- openssl_spki_verify — 署名済みの公開鍵とチャレンジを検証する
- openssl_verify — 署名を検証する
- openssl_x509_check_private_key — 秘密鍵が証明書に対応するかを確認する
- openssl_x509_checkpurpose — 証明書が特定の目的に使用可能かどうか確認する
- openssl_x509_export — 証明書を文字列としてエクスポートする
- openssl_x509_export_to_file — 証明書をファイルにエクスポートする
- openssl_x509_fingerprint — 与えられた X.509 証明書のフィンガープリントあるいはダイジェストを計算する
- openssl_x509_free — 証明書リソースを開放する
- openssl_x509_parse — X509 証明書をパースし、配列として情報を返す
- openssl_x509_read — X.509 証明書をパースし、オブジェクトを返す
- openssl_x509_verify — x509証明書のデジタル署名を公開鍵で検証する
+add a note
User Contributed Notes 24 notes
dan -AT- NOSPAM danschafer DOT netTT ¶
17 years ago
Currently, all OpenSSL Functions defined in PHP only utilize the PEM format. Use the following code to convert from DER to PEM and PEM to DER.
<?php
$pem_data = file_get_contents($cert_path.$pem_file);
$pem2der = pem2der($pem_data);
$der_data = file_get_contents($cert_path.$der_file);
$der2pem = der2pem($der_data);
function pem2der($pem_data) {
$begin = "CERTIFICATE-----";
$end = "-----END";
$pem_data = substr($pem_data, strpos($pem_data, $begin)+strlen($begin));
$pem_data = substr($pem_data, 0, strpos($pem_data, $end));
$der = base64_decode($pem_data);
return $der;
}
function der2pem($der_data) {
$pem = chunk_split(base64_encode($der_data), 64, "\n");
$pem = "-----BEGIN CERTIFICATE-----\n".$pem."-----END CERTIFICATE-----\n";
return $pem;
}
?>
skippy zuavra net ¶
19 years ago
In case you're wondering what's a "correctly hashed" directory for the use with cainfo: it's simply a directory which contains CA public certificates in PEM/X.509 format. You can get such certificates either from the CA's website (they advertise it in visible places) or from your browser. In Explorer for instance you can click on the little yellow padlock, go to the CA entry and export it.
The only trick with the directory is that file names must be in the form "hash.#". The "hash" part is the 8-digit hex hash of the certificate, while the # part is a number which serves to differentiate certificates which give the same hash (yes, it can happen with certificates coming from the same CA). Usually # is 0, but you also can use 1, 2 and so on when having more certs with the same hash.
In order to obtain the hash of a certificate you can use the openssl command line utility like this:
openssl x509 -hash -in certfile.cer | head -1
peter dot mescalchin @ geemail dot com ¶
18 years ago
For w32 users to enable OpenSSL support. As well as copying "libeay32.dll" to the windows system32 folder you also need to copy "ssleay32.dll". The documentation above should probably be updated to note this.
This requirement was documented at the libcurl pages:
http://curl.haxx.se/libcurl/php/install.html#windows
kraven at kraven dot org ¶
11 years ago
If you want to verify that a csr was generated properly from your private key you can do the following:
<?php
$countryName = "UK";
$stateOrProvinceName = "London";
$localityName = "Blah";
$organizationName = "Blah1";
$organizationalUnitName = "Blah2";
$commonName = "Joe Bloggs";
$emailAddress = "openssl@example.com";
$dn = array(
"countryName" => $countryName,
"stateOrProvinceName" => $stateOrProvinceName,
"localityName" => $localityName,
"organizationName" => $organizationName,
"organizationalUnitName" => $organizationalUnitName,
"commonName" => $commonName,
"emailAddress" => $emailAddress
);
$badPriv = 'foo';
// generate a bad csr
$badCsr = openssl_csr_new($dn, $badPriv);
// generate private key
$priv = openssl_pkey_new();
// generate csr
$csr = openssl_csr_new($dn, $priv);
$badCsrDetails = openssl_pkey_get_details(openssl_csr_get_public_key($badCsr));
$privDetails = openssl_pkey_get_details($priv);
$csrDetails = openssl_pkey_get_details(openssl_csr_get_public_key($csr));
echo md5($badCsrDetails['rsa']['n']);
echo "\nDoes not match\n";
echo md5($privDetails['rsa']['n']);
echo "\nMatches\n";
echo md5($csrDetails['rsa']['n']);
echo "\n";
?>
This output is an md5 hash of the modulus. The same check can be accomplished with openssl:
openssl rsa -noout -modulus -in server.key | openssl md5
openssl req -noout -modulus -in server.csr | openssl md5
jts ¶
16 years ago
Win32 users having trouble getting php_openssl to work should make sure that they replace ALL the versions of libeay32.dll and ssleay32.dll, with the ones included with PHP. This is especially true while using Apache2 and OpenSSL together, as some OpenSSL win32 packages include older versions of these two files.
greensweater ¶
19 years ago
"You need to have a valid openssl.cnf installed for this function to operate correctly" includes most openssl functions. You can force php to find your openssl.cnf file as follows:
$config = array('config'=>'/path/to/openssl.cnf');
$pkey = openssl_pkey_new($config);
$csr = openssl_csr_new('MyCSR',$pkey,$config);
rahuul at yours dot com ¶
14 years ago
for changing serial no of cert following is the solution:
<?php
$sscert = openssl_csr_sign($csr, $cacert, $privkey, $days,$config,$serial);
?>
yabba dabba ¶
18 years ago
The php4 distribution for Windows/IIS has a README-SSL.txt which strongly implies that just the path needs to be added to the OPENSLL_CONF variable in the server's environment variables. Be sure to add the file name and extension too.
E.g.: c:\php-4.3.11\openssl\openssl.cnf
web at mburda dot com ¶
16 years ago
There is a little problem with Matt Alexander's code below.
Both public and private key are generated internally and saved into OpenSSL class object properties but only private key is then used.
Public key is taken from an external file and if it differs from the one stored internally, OpenSSL fails to decrypt the text.