Skip to content
Advertisement

SSL: match private key with certificate using PHP (without phpseclib)

I have tried to use this PHP code script to check SSL private key with SSL certificate match or not the result is match every time.

JavaScript

this function use openssl by shell_exec it can export files server.crt, server.key, server.csr

JavaScript

but when i use this shell_exec for check $pkey_check & $cert_check match or not it still result match every time. Because $pkey_check & $cert_check = null

JavaScript

Result of above script

Export Cert OK = /tmp/41893.server.crt

Export Pkey OK = /tmp/41893.server.key

cert_check =

pkey_check =

Match

I have try another shell_exec but the same resutl

JavaScript

Advertisement

Answer

(Posted on behalf of the question author).

This simple script use to check private key & certificate match or not.

JavaScript

Define $cert and $pkey (or use $_POST[$cert] and $_POST[$pkey] instead)

JavaScript

Call function check_pkey_cert_match() and result.

JavaScript

Just use Function openssl_x509_check_private_key()

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement