简体   繁体   English

如何验证公钥属于私钥?

[英]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. 我将PHP 5.3与openssl一起使用以成功生成一对公共密钥和私有密钥。

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. 密钥是成对生成的,因此对于给定的私钥,公钥将始终相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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