情况:我有一个服务器管理员面板,用户应该可以上传私钥/证书/证书(/ CSR)以进行SSL网站保护。
上传的数据如下所示:
私钥=
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA3u+SI24XGAqIHNLcmCfEFOpMVAOEZOw3DpZ7VexB6soLiu0a
[...]
M9YQw2MV/EhNXTh7PW85HJKAZyTxLJvWIXbEeY9XX+GkqJuQ1GhfgfE=
-----END RSA PRIVATE KEY-----
certificate =
-----BEGIN CERTIFICATE-----
MIIDfjCCAmigAwIBAgIEU6fNGzALBgkqhkiG9w0BAQUwgYExCzAJBgNVBAYMAkRF
[...]
oosSAukE596+wwM0XXDFOT2T/D0lHvW1QVyFx0GzCRHWqQ==
-----END CERTIFICATE-----
问题:上传后,我需要检查cert / ca-cert是否与私钥(/ CSR)匹配,以确保所有上传的部分都在一起。
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
(我想坚持使用phpseclib,所以openssl不是一个选项)
非常感谢你!
答案 0 :(得分:2)
这样的事情可以解决问题吗?:
$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";
}