简体   繁体   中英

How to verify that a public key belongs to private key?

I am using PHP 5.3 with openssl to successfully generate a pair of public key and private key.

Lets say someone passes me a public key only.

How can I verify that this public key belongs to a private key that I have? (only by having the public key and a private key, no additional data)

Encrypt a message with the public key and see if you can decrypt it with the private key.

Alternatively, you could just extract the public key from your private key file and compare it to the public key that someone passed to you. Keys are generated in pairs, so for a given private key, the public key will always be the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM