This is my first encryption try out. This is my code:
$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 );
I get the following errors;
Warning: openssl_pkey_export_to_file(): cannot get key from parameter 1 in C:\xampp\htdocs\PHP\25000.php on line 40
Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\PHP\25000.php on line 43
Warning: openssl_free_key() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\PHP\25000.php on line 48
I already searched SO. I found that I have to do following:
- Install OpenSSL in XAMPP
- Turn on PHP and Apache SSL mods
I am not sure if I have done these and I wonder if that is the reason for my error?