gpt4 book ai didi

php openssl : how to match the private key with the certificate

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:05 25 4
gpt4 key购买 nike

我有一个自签名签名,其中包含证书本身和私钥。我的目的是检查此私钥是否与证书匹配。我所做的是:

$private = openssl_pkey_get_private("path/to/certificate");
$public = openssl_pkey_get_public("path/to/certificate");
openssl_sign("path/to/certificate", $sig, $private);

所以我根据文件中的私钥和公钥创建签名。所以我需要做的是将这个签名与证书中现有的签名进行比较。如果它们匹配,则意味着私钥匹配。但是,我无法从文件中检索现有的签名信息。我想知道我的方法是否正确,因为我在谷歌上找不到任何信息。

谢谢。

最佳答案

如果您只想检查私钥和证书是否匹配,您可以调用openssl_x509_check_private_key。它以证书和私钥作为输入并返回它们是否匹配。查看文档 here .

编辑:另外请注意,证书中的签名是使用组成证书的不同信息到达的,而您传递给 openssl_sign 函数的数据只是证书的路径。因此,即使您最终确定了一种从证书中提取签名的方法,它仍然不会与 openssl_sign 的输出匹配(绝对不会与您传递给 openssl_sign 的 $data 匹配)。

关于php openssl : how to match the private key with the certificate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18981671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com