D
D
Daniil Sukhikh2021-12-05 20:35:50
PHP
Daniil Sukhikh, 2021-12-05 20:35:50

How to get a public key from a stored private?

I wrote my own script for encrypting and decrypting messages.

$nKey = openssl_pkey_new();
openssl_pkey_export($nKey, $pKey);

$uKey = openssl_pkey_get_details($nKey);
$uKey = $uKey['key'];

$data = 'Привет игорь!';

openssl_public_encrypt($data, $nData, $uKey);

echo base64_encode($nData) . "<br>";

openssl_private_decrypt($nData,$dData, $pKey);

echo $dData . "<br>";

As you can see above, encryption and decryption takes place in one script, according to my logic, I will store the private key with myself and create the public key for users.
Questions:
1. How can I create new ones based on the stored private key?
2. What is the best way for me to store the private key and work with it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
CityCat4, 2021-12-05
@CityCat4

How can I create new publics based on the stored private key?

No way :) The public key is created at the same moment as the private one, and they are a pair of keys - one private key corresponds to one public one.

L
Lynn "Coffee Man", 2021-12-05
@Lynn

I don’t know how in php, but everything is simple in the console
https://stackoverflow.com/a/5246045/1016033

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question