src/CfdiUtils/Certificado/Certificado.php
public function belongsTo(string $pemKeyFile, string $passPhrase = ''): bool
    {
        $this->assertFileExists($pemKeyFile);
        $openSSL = $this->getOpenSSL();
        $keyContents = $openSSL->readPemContents(
            // intentionally silence this error, if return false then cast it to string
            strval(@file_get_contents($pemKeyFile))
        )->privateKey();
        if ('' === $keyContents) {
            throw new \UnexpectedValueException("The file $pemKeyFile is not a PEM private key");
        }
        $privateKey = openssl_get_privatekey($keyContents, $passPhrase);
        if (false === $privateKey) {
            throw new \RuntimeException("Cannot open the private key file $pemKeyFile");
        }
        $belongs = openssl_x509_check_private_key($this->getPemContents(), $privateKey);
        openssl_free_key($privateKey);
        return $belongs;
    }
public function belongsTo(string $pemKeyFile, string $passPhrase = ''): bool
    {
        $this->assertFileExists($pemKeyFile);
        $openSSL = $this->getOpenSSL();
        $keyContents = $openSSL->readPemContents(
            // intentionally silence this error, if return false then cast it to string
            strval(@file_get_contents($pemKeyFile))
        )->privateKey();
        if ('' === $keyContents) {
            throw new \UnexpectedValueException("The file $pemKeyFile is not a PEM private key");
        }
        $privateKey = openssl_get_privatekey($keyContents, $passPhrase);
        if (false === $privateKey) {
            throw new \RuntimeException("Cannot open the private key file $pemKeyFile");
        }
        $belongs = openssl_x509_check_private_key($this->getPemContents(), $privateKey);
        openssl_free_key($privateKey);
        return $belongs;
    }
public function belongsTo ( string $ pemKeyFile , string $ passPhrase = '' ) : bool { $ this -> assertFileExists ( $ pemKeyFile ) ; $ openSSL = $ this -> getOpenSSL ( ) ; $ keyContents = $ openSSL -> readPemContents ( // intentionally silence this error, if return false then cast it to string strval ( @ file_get_contents ( $ pemKeyFile ) ) ) -> privateKey ( ) ; if ( '' === $ keyContents ) { throw new \ UnexpectedValueException ( "The file $pemKeyFile is not a PEM private key" ) ; } $ privateKey = openssl_get_privatekey ( $ keyContents , $ passPhrase ) ; if ( false === $ privateKey ) { throw new \ RuntimeException ( "Cannot open the private key file $pemKeyFile" ) ; } $ belongs = openssl_x509_check_private_key ( $ this -> getPemContents ( ) , $ privateKey ) ; openssl_free_key ( $ privateKey ) ; return $ belongs ; }
Check if this certificate belongs to a private key

@param string $pemKeyFile
@param string $passPhrase

@return bool

@throws \UnexpectedValueException if the file does not exists or is not readable
@throws \UnexpectedValueException if the file is not a PEM private key
@throws \RuntimeException if cannot open the private key file
Check if this certificate belongs to a private key