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(): cannot get key from parameter 1 in C:\xampp\htdocs\PHP\25000.php on line 40

警告:openssl_pkey_get_details() 期望参数 1 是资源,布尔值在第 43 行的 C:\xampp\htdocs\PHP\25000.php 中给出

警告:openssl_free_key() 期望参数 1 是资源,布尔值在第 48 行的 C:\xampp\htdocs\PHP\25000.php 中给出

我已经搜索过了。我发现我必须做以下事情:

  • 在 XAMPP 中安装 OpenSSL
  • 打开PHP和 Apache SSL 模组

我不确定我是否做了这些,我想知道这是否是我错误的原因?

4

0 回答 0