简体   繁体   English

ssl:将私钥与证书匹配| 使用php&phpseclib

[英]ssl: match private key with certificat | using php & phpseclib

situation: i have a server-admin-panel, where the user should be able to upload a private key / certificate / ca-certificate ( / CSR) for SSL website protection. 情况:我有一个服务器管理面板,用户应能够上载私钥/证书/ ca证书(/ CSR)以保护SSL网站。

The uploaded data would look like this: 上传的数据如下所示:

private key = 私钥=

-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA3u+SI24XGAqIHNLcmCfEFOpMVAOEZOw3DpZ7VexB6soLiu0a
[...]
M9YQw2MV/EhNXTh7PW85HJKAZyTxLJvWIXbEeY9XX+GkqJuQ1GhfgfE=
-----END RSA PRIVATE KEY-----

certificate = 证书=

-----BEGIN CERTIFICATE-----
MIIDfjCCAmigAwIBAgIEU6fNGzALBgkqhkiG9w0BAQUwgYExCzAJBgNVBAYMAkRF
[...]
oosSAukE596+wwM0XXDFOT2T/D0lHvW1QVyFx0GzCRHWqQ==
-----END CERTIFICATE-----

problem: after uploading, i need to check, if cert / ca-cert match the private key ( / CSR), to ensure, that all the uploaded parts belong together. 问题:上传后,我需要检查cert / ca-cert是否与私钥(/ CSR)匹配,以确保所有上传的部分都属于同一部分。


i think i'm stuck. 我想我被卡住了。 With openssl i could check if the output of the following command matches each other. 使用openssl,我可以检查以下命令的输出是否相互匹配。 But i don't know how to do this with phpseclib. 但是我不知道如何用phpseclib做到这一点。

openssl x509 -noout -modulus -in certificate.crt | openssl md5
openssl rsa -noout -modulus -in privateKey.key | openssl md5
openssl req -noout -modulus -in CSR.csr | openssl md5

(i would like to stick with phpseclib, so openssl is not an option) (我想坚持使用phpseclib,所以不可能使用openssl)

Thank you very very much! 非常非常感谢你!

Something like this do the trick?: 这样的东西可以解决问题吗?:

$rsa = new Crypt_RSA();
$rsa->loadKey(...);
$pubkey1 = $rsa->getPublicKey();

$x509 = new File_X509();
$x509->loadX509(...);
$pubkey2 = $x509->getPublicKey();

$csr = new File_X509();
$csr->loadCSR(...);
$pubkey3 = $csr->getPublicKey();

if (($pubkey1 == $pubkey2) && ($pubkey2 == $pubkey3)) {
    echo "they're equal";
} else {
    echo "they're not equal";
}

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

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