0

これは私の最初の暗号化の試みです。これは私のコードです:

$privateKey = openssl_pkey_new(array(
    'private_key_bits' => 2048, //size of key
    'private_key_type' => OPENSSL_KEYTYPE_RSA,
));

//save the private key to private.key file. Never share this file with anyone.
openssl_pkey_export_to_file( $privateKey, 'private.key' );

//generate the public key for the private key
$a_key = openssl_pkey_get_details( $privateKey );
//save the public key in public.key file. Send this file to anyone who wants to send you the encrypted data.
file_put_contents( 'public.key', $a_key['key'] );

//free the private key
openssl_free_key( $privateKey );

次のエラーが表示されます。

警告: openssl_pkey_export_to_file(): C:\xampp\htdocs\PHP\25000.php の 40 行目のパラメーター 1 からキーを取得できません

警告: openssl_pkey_get_details() は、パラメーター 1 がリソースであると想定しており、43 行目の C:\xampp\htdocs\PHP\25000.php で指定されたブール値です。

警告: openssl_free_key() は、パラメーター 1 がリソースであると想定し、48 行目の C:\xampp\htdocs\PHP\25000.php で指定されたブール値です。

私はすでにSOを検索しました。私は次のことをしなければならないことがわかりました:

  • XAMPP に OpenSSL をインストールする
  • PHPと Apache SSL mod を有効にする

これらを行ったかどうかはわかりませんが、それがエラーの理由なのだろうか?

4

0 に答える 0